Hexadecimal numbers

By Martin McBride, 2016-11-27
Tags: binary hexadecimal
Categories: numbers

Binary numbers can be difficult to read, and difficult to type in without error. With a long string of ones and zeros, it is very easy to make a mistake. Hexadecimal notation makes this a lot easier.

Hexadecimal is often shortened to hex.

Hexadecimal

A group of 4 bits can take any value between 0 (0000 binary) and 15 (1111 binary).

In hexadecimal, we replace each group of 4 bits with a single digit to represent the value 0 to 15. Since we only have digits 0 to 9, we use letters A to E to represent values 10 to 15. Here is a table of binary, denary and hex values:

Hex table

Hexadecimal numbers are often written in the form:

0x1A3C

Letters are usually not case sensitive, so you can also write

0x1a3c

Converting binary to hex

To convert the binary number 01101100 to hex:

  • Split the binary into groups of 4 bits, in this case 0110 1100
  • Look up each group in the table (binary -> hex), in this case we get 6 and C
  • Put the digits together, e.g. 0x6C

Converting hex to binary

To convert the hex number 0xfe to binary:

  • Look up each digit on the table (hex -> binary), in this case f gives us 1111, e gives us 1110
  • Join the groups of 4 bits, in this case 11111110

See also

Sign up to the Creative Coding Newletter

Join my newsletter to receive occasional emails when new content is added, using the form below:

Popular tags

555 timer abstract data type abstraction addition algorithm and gate array ascii ascii85 base32 base64 battery binary binary encoding binary search bit block cipher block padding byte canvas colour coming soon computer music condition cryptographic attacks cryptography decomposition decryption deduplication dictionary attack encryption file server flash memory hard drive hashing hexadecimal hmac html image insertion sort ip address key derivation lamp linear search list mac mac address mesh network message authentication code music nand gate network storage none nor gate not gate op-amp or gate pixel private key python quantisation queue raid ram relational operator resources rgb rom search sort sound synthesis ssd star network supercollider svg switch symmetric encryption truth table turtle graphics yenc