Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8627981
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:25:06+00:00 2026-06-12T08:25:06+00:00

I’m curious why the result of SHA256 can be saved within a binary(32) ,

  • 0

I’m curious why the result of SHA256 can be saved within a binary(32), but it needs a varchar(64) for the same result to be saved.

I mean, 256 bits are 32 bytes, so, saving inside a binary(32) makes perfect sense. But then why trying to save it in a varchar requires an extra byte for each byte?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T08:25:07+00:00Added an answer on June 12, 2026 at 8:25 am

    Let’s start at the beginning and see what a cryptographic function is and what it’s output actually is:

    A cryptographic hash function is a hash function, that is, an
    algorithm that takes an arbitrary block of data and returns a
    fixed-size bit string, the (cryptographic) hash value.

    That means that we obtain sequence of 1s and 0s back. In order to save that sequence correctly, you have to use MySQL’s binary data-type column since it doesn’t save any data about how to represent the saved data to the user – there is no encoding associated with it. That means that when you try to view the data, you’ll most likely see garbled characters since the GUI programs will attempt to represent the value stored as an ASCII-encoded string (which is wrong).

    I’ll skip the reasons why the hash value is represented as a number, but the point is that it is. And it’s a hexadecimal number. Let’s take the 1st byte that you used:

    10101111 = that’s decimal 175 or hexadecimal AF.

    Sure, you can represent ASCII 175 as something, it will most likely be a weird character depending on the codepage being used. Problem with ASCII is that codes above 127 are arbitrary, which lead to inventing codepages, which lead to inventing Unicode etc. so I’ll skip it for now.

    Point is, you can’t rely on ASCII displaying 10101111 correctly in every scenario.
    That means that 175 will have to be displayed using 3 bytes, not 1. Why? Because each character in 175 has to be displayed using its own byte.

    That means that you can display your hash value as decimal number. That also means you can display your number as a hexadecimal number, which is significantly shorter to represent.

    Let’s take 10101111 again.

    In decimal it’s 175, takes 3 bytes to show it on screen – 1 for 1, 1 for 7 and 1 for 5.
    In hexadecimal it’s AF, takes 2 bytes to show it on screen – significantly shorter.

    Each byte when translated to hex number has at least 2 digits (there are leading zeroes). With decimal numbers that’s not the case, so you know that every time you want to represent 1 byte as a hex number – you’d have at least 2 digits. Ergo, your message is fixed width, it uses digits 0-9, letters A-F which are at the same position in every ASCII code page, ergo they’ll look the same.

    So when you take AF and display it in ASCII, you need 1 byte for A and 1 byte for F.
    There are 32 numbers, each has 2 digits, 32×2 = 64 bytes.

    The only mistake you probably did was using varchar(64). Using varchar for storing hashes is useless, if you know the hash width. Using char would be much better because you wouldn’t waste that 1 byte that varchar column uses.

    Hopefully, this clears it up a bit. It’s actually more simple than it sounds 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
I want to construct a data frame in an Rcpp function, but when I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.