Reading — step 1 of 5
Read
~1 min readBits, Bytes & Endianness
Big-Endian Word Packing
SHA-256 operates on 32-bit words, but its input is bytes. The convention is big-endian: the high byte first.
bytes: 61 62 63 64 (ASCII 'a','b','c','d')
big-endian word: 0x61626364 ('abcd' as one 32-bit number)
Most modern x86/ARM CPUs are little-endian, so you must explicitly pack big-endian:
python
To unpack a 256-bit hash (the final output) back to bytes, also big-endian:
python
The full output is 8 such words concatenated = 32 bytes = 64 hex chars.
Why big-endian? Network byte order. SHA, MD5, SHA-1, AES, etc. all use big-endian for interop with network protocols.
Discussion
Ask a question, share an insight, or help someone who’s stuck.
Sign in to post a comment or reply.
Loading…