Skip to content

Instantly share code, notes, and snippets.

@scottmwyant
Created July 8, 2022 11:41
Show Gist options
  • Save scottmwyant/d389f5d808533c33d070b081f0e3d125 to your computer and use it in GitHub Desktop.
Save scottmwyant/d389f5d808533c33d070b081f0e3d125 to your computer and use it in GitHub Desktop.
Binary to Hexidecimal

Converting binary to hexadecimal (base 16)

Start with a given binary string: 1111011111100

1. Break the string up into groups of 4 bits.

Start from the right. Should the last grouping not have four bits, fill in with 0.

1 1110 1111 1100 = 0001 1110 1111 1100

2. Calculate the decimal equivalent for each 4-bit group

1 14, 15 12

3. Replace numbers [10-15] with letters [A-F]

Replace two character integers with a single alphabetic character, 10=A, 11=B, 12=C, 13=D, 14=E, 15=F. The maximum decimal value for a 4-bit grouping is 15, as demonstrated in this exapmle.

1, E, F, C

1111011111100 = #1EFC

Reference https://www.youtube.com/watch?v=tSLKOKGQq0Y

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment