EMZETT.
Login

Calculating in binary, decimal and hexadecimal

In short: Computers calculate in the binary system (base 2). Decimal (10) and hexadecimal (16) are representations people read. Converting is a standard task in IT exams.

In more detail: Each position of a binary number has the value of a power of two (…, 8, 4, 2, 1). Hexadecimal groups 4 bits into one digit (0 to 9, A to F). That is why hex is a compact notation for bytes: 8 bits = two hex digits.

Our context: The calculator and the subnet calculator show the working.

In Depth

Decimal → binary (division by 2): 45 ÷ 2 = 22 remainder 1; 22 ÷ 2 = 11 remainder 0; 11 ÷ 2 = 5 remainder 1; 5 ÷ 2 = 2 remainder 1; 2 ÷ 2 = 1 remainder 0; 1 ÷ 2 = 0 remainder 1. Remainders from bottom to top: 101101.

Binary → decimal: 101101 = 32 + 8 + 4 + 1 = 45.

Binary → hex: in groups of 4 from the right: 0010 1101 = 2 D → 0x2D.

Hex → decimal: 0x2D = 2 · 16 + 13 = 45.

  • Value range: n bits represent 2ⁿ values (8 bits: 0 to 255).
  • Two’s complement: Negative numbers: invert the bits and add 1. −5 in 8 bits = 11111011.
  • Units: 1 KiB = 1,024 bytes, 1 kB = 1,000 bytes.
  • Use: colour codes (#FF8800), MAC addresses, IPv6, subnet masks (subnet mask, subnet).

See also: Units and conversion (SI, byte, temperature), Hex codes