One byte
11010110
D6
1101 is 13, written D, and 0110 is 6.
Type a binary number and read it in hexadecimal, with each group of four bits shown underneath. It opens on 11010110, which is D6.
Last updated
Coddy teaches you by writing real code in your browser - interactive lessons, instant feedback, and AI help when you get stuck.
Four bits have sixteen combinations, the same number as there are hex digits, so every group of four becomes exactly one hex digit. Work from the right because that is where the groups line up; if the leftmost group is short, add zeros in front of it.
To turn a group into a digit, add the place values of its 1s: 8, 4, 2 and 1. 1101 is 8 + 4 + 1 = 13, which is D, and 0110 is 4 + 2 = 6.
This is why programmers write binary data in hex. A 32-bit value is 32 hard-to-read bits but only 8 hex digits.
chmod numbers.11010110
D6
1101 is 13, written D, and 0110 is 6.
101
5
Pad it to 0101, which is 5.
1 0110 1011
16B
Grouping from the right leaves a single 1 on the left, which pads to 0001 and becomes 1.
1111 1111 1111 1111
FFFF
Every group is 1111, so every digit is F. This is 65535, the largest 16-bit value.
10110 gives 1011 and a stray 0; grouped from the right it is 0001 0110, which is 16.hex(int('11010110', 2)) returns '0xd6'. In JavaScript, parseInt('11010110', 2).toString(16) returns 'd6'.