This post is the 2nd in a series about basic concepts in programming and Computer Science. You can find all the posts in the series below.

  1. CS Basics: Binary Conversion
  2. CS Basics: Hex and 32 Bit Conversion
  3. CS Basics: Detour - Nibbles, MSB, and LSB
  4. CS Basics: Converting Between Different Bases

In the last post in this series, we covered converting binary, quaternary, and octal numbers. Now we’ll go through hexadecimal and 32 bit numbers. If you haven’t read the first post, go ahead and read it now then come back.

Converting hex and 32 bit numbers is pretty close to the same as converting smaller bases, but there’s one important difference — we have to be able to account for numbers larger than 9.

We already know that the decimal system, or regular integers, can go from 0 - 9 in each digit. The trouble with something like hexadecimal, or Base16, numbers (and higher) is that there’s no way to represent something larger than 9 with a single-digit integer.

So what do we do?

Well, we use letter characters.

For hex and 32-bit numbers 0 - 9 are the same as decimal. When the digit gets larger than 9 we use letters.

Hex: 1 - 9, A - F

32 Bit: 1 - 9, A - V

That’s it!

Hexadecimal (Base16)

65536 4096 256 16 1
0 0
1 1
10 A
11 B
12 C
13 D
14 E
15 F
16 1 0
17 1 1
26 1 A

As you can see, each digit in hexadecimal can represent 16 unique numbers.

Two digits can represent 256 unique numbers. If you’ve used hex colors, you’re using hexadecimal numbers with six digits. That’s 256 3 , or 16,777,216, color values.

Honestly, this table could go on forever, so I’m going to whip up a hex multiplication table with client-side JavaScript and you can use that for reference if you need to.

JavaScript provides some nice convenience methods for converting a binary number to a different base representation. To get the values for the table below, all I had to do was multiply two values and then write cellValue = product.toString(16), which will convert an integer to a string that represents the given base’s value.

0123456789ABCDEF
00000000000000000
10123456789ABCDEF
202468ACE10121416181A1C1E
30369CF1215181B1E2124272A2D
4048C1014181C2024282C3034383C
505AF14191E23282D32373C41464B
606C12181E242A30363C42484E545A
707E151C232A31383F464D545B6269
8081018202830384048505860687078
909121B242D363F48515A636C757E87
A0A141E28323C46505A646E78828C96
B0B16212C37424D58636E79848F9AA5
C0C1824303C4854606C7884909CA8B4
D0D1A2734414E5B6875828F9CA9B6C3
E0E1C2A38465462707E8C9AA8B6C4D2
F0F1E2D3C4B5A69788796A5B4C3D2E1

So, that leaves 32-bit conversions. Those behave exactly the same as hexadecimal conversions, but since we’re dealing with numbers larger than 15, we need to include additional substitution characters.

Two 32-bit digits can account for 1,024 decimal numbers.

Here’s a 32-bit table (hopefully the table works for smaller screens, because it’s going to be pretty big).

0123456789ABCDEFGHIJKLMNOPQRSTUV
000000000000000000000000000000000
10123456789ABCDEFGHIJKLMNOPQRSTUV
202468ACEGIKMOQSU10121416181A1C1E1G1I1K1M1O1Q1S1U
30369CFILORU1114171A1D1G1J1M1P1S1V2225282B2E2H2K2N2Q2T
4048CGKOS1014181C1G1K1O1S2024282C2G2K2O2S3034383C3G3K3O3S
505AFKPU13181D1I1N1S21262B2G2L2Q2V34393E3J3O3T42474C4H4M4R
606CIOU141A1G1M1S22282E2K2Q30363C3I3O3U444A4G4M4S52585E5K5Q
707ELS131A1H1O1V262D2K2R32393G3N3U454C4J4Q51585F5M5T646B6I6P
808GO10181G1O20282G2O30383G3O40484G4O50585G5O60686G6O70787G7O
909IR141D1M1V282H2Q333C3L3U474G4P525B5K5T666F6O717A7J7S858E8N
A0AKU181I1S262G2Q343E3O424C4M505A5K5U686I6S767G7Q848E8O929C9M
B0BM111C1N222D2O333E3P444F4Q555G5R666H6S777I7T888J8U999K9VAAAL
C0CO141G1S282K303C3O444G4S585K606C6O747G7S888K909C9OA4AGASB8BK
D0DQ171K212E2R383L424F4S595M636G6T7A7N848H8U9B9OA5AIAVBCBPC6CJ
E0ES1A1O262K323G3U4C4Q585M646I707E7S8A8O969KA2AGAUBCBQC8CMD4DI
F0FU1D1S2B2Q393O474M555K636I717G7V8E8T9C9RAAAPB8BNC6CLD4DJE2EH
G0G101G202G303G404G505G606G707G808G909GA0AGB0BGC0CGD0DGE0EGF0FG
H0H121J242L363N484P5A5R6C6T7E7V8G919IA3AKB5BMC7COD9DQEBESFDFUGF
I0I141M282Q3C3U4G525K666O7A7S8E909IA4AMB8BQCCCUDGE2EKF6FOGAGSHE
J0J161P2C2V3I454O5B5U6H747N8A8T9GA3AMB9BSCFD2DLE8ERFEG1GKH7HQID
K0K181S2G343O4C505K686S7G848O9CA0AKB8BSCGD4DOECF0FKG8GSHGI4IOJC
L0L1A1V2K393U4J585T6I777S8H969RAGB5BQCFD4DPEEF3FOGDH2HNICJ1JMKB
M0M1C222O3E444Q5G666S7I888U9KAAB0BMCCD2DOEEF4FQGGH6HSIIJ8JUKKLA
N0N1E252S3J4A515O6F767T8K9BA2APBGC7CUDLECF3FQGHH8HVIMJDK4KRLIM9
O0O1G28303O4G58606O7G88909OAGB8C0CODGE8F0FOGGH8I0IOJGK8L0LOMGN8
P0P1I2B343T4M5F68717Q8J9CA5AUBNCGD9E2ERFKGDH6HVIOJHKAL3LSMLNEO7
Q0Q1K2E38424S5M6G7A848U9OAIBCC6D0DQEKFEG8H2HSIMJGKAL4LUMONIOCP6
R0R1M2H3C47525T6O7J8E99A4AVBQCLDGEBF6G1GSHNIIJDK8L3LUMPNKOFPAQ5
S0S1O2K3G4C5864707S8O9KAGBCC8D4E0ESFOGKHGICJ8K4L0LSMONKOGPCQ8R4
T0T1Q2N3K4H5E6B7885929VASBPCMDJEGFDGAH7I4J1JUKRLOMLNIOFPCQ9R6S3
U0U1S2Q3O4M5K6I7G8E9CAAB8C6D4E2F0FUGSHQIOJMKKLIMGNEOCPAQ8R6S4T2
V0V1U2T3S4R5Q6P7O8N9MALBKCJDIEHFGGFHEIDJCKBLAM9N8O7P6Q5R4S3T2U1

Next time we’ll go over converting from one non-decimal base, like binary, to another base, like hex.