Digital Logic · AI215

Number System Conversion: Binary, Octal, Decimal and Hexadecimal

Digital Logic Study guides

Every positional number system has a base. Digital logic uses binary (base 2), with octal (base 8) and hexadecimal (base 16) as compact shorthand.

In a positional system the value of a digit is the digit times the base raised to its position. Decimal is base 10 with digits 0 to 9, binary is base 2 with digits 0 and 1, octal is base 8 with digits 0 to 7, and hexadecimal is base 16 with digits 0 to 9 and A to F (A = 10 up to F = 15). Hexadecimal is the number system that uses letters as well as numerals. With n bits you can represent 2 to the power n values, from 0 to 2^n - 1; with 4 bits, 0 to 15.

Decimal to any base: for the integer part divide repeatedly by the base and read the remainders from last to first. For the fraction part multiply repeatedly by the base and read the integer parts from first to last. Any base to decimal: multiply each digit by its place value and add; digits after the point have negative powers.

Binary to octal: group bits in threes starting at the point (pad with zeros), and each group is one octal digit. Binary to hexadecimal: group in fours. Going back, expand each octal digit to 3 bits or each hex digit to 4 bits. No arithmetic is needed, which is why octal and hex are used as shorthand for long binary strings.

Key points

  • Value = sum of digit x base^position.
  • Integer part: divide by base, read remainders upward. Fraction: multiply by base, read integer parts downward.
  • Binary to octal: groups of 3 bits. Binary to hex: groups of 4 bits.
  • Hex digits A to F are 10 to 15.
  • n bits give 2^n combinations.

Worked example

Convert 29.625 (decimal) to binary. Integer 29: 29/2=14 r1, 14/2=7 r0, 7/2=3 r1, 3/2=1 r1, 1/2=0 r1, so 11101. Fraction 0.625: x2=1.25 gives 1, 0.25x2=0.5 gives 0, 0.5x2=1.0 gives 1, so .101. Result: 11101.101. In octal: 011 101 . 101 = 35.5. In hex: 0001 1101 . 1010 = 1D.A.

Common questions

How do you convert binary to hexadecimal?

Group the bits in fours from the binary point and replace each group with its hex digit.

How many values can n bits represent?

2 to the power n, from 0 to 2^n - 1 for unsigned numbers.

Practice questions on this topic

Try these, then open the app to check your answers with explanations.

  1. Base of Hexadecimal number system is?
    • A. 16
    • B. 8
    • C. 2
    • D. 10
  2. Which type of number system is represented by base 8 ?
    • A. Decimal
    • B. Binary
    • C. Octal
    • D. hexadecimal
  3. Convert the numbers from decimal to binary (29.625)₁₀?
    • A. (11101.111)₂
    • B. (11111.001)₂
    • C. (11101.101)₂
    • D. (111.0011)₂
  4. Which of these are types of number system?
    • A. Binary system
    • B. Decimal system
    • C. Octal system
    • D. All of this
  5. Base of octal number system is?
    • A. 2
    • B. 5
    • C. 8
    • D. 16
  6. Convert the numbers from decimal to octal (65)₁₀?
    • A. (43)₈
    • B. (101)₈
    • C. (56)₈
    • D. (68)₈