Binary, decimal, hex number systems (CS framing)

Computer Science · Foundations

Question 1 of 10

0

    What is the decimal value of the binary number 1110?

    Decimals (0.75 or 0,75), fractions (3/4) and mixed numbers (1 1/2) are accepted. Do not use thousands separators.

    How to type your answer
    • Fractions: 3/4. Mixed numbers: 1 1/2.
    • Decimals with a point or a comma: 0.75 or 0,75.
    • Negative numbers start with a minus: -3/4.
    • Percentages need the % sign: 75%.

    Stuck? Read the explanation

    Unlocks at a streak of 5 correct answers in a row.

    Print a free worksheet (PDF)

    Embed this practice on your site or class page

    Paste this HTML into your page. Students practise right there; it is free and needs no account.

    Binary, decimal, hex number systems (CS framing) explained

    Computers store everything as bits, which can only be 0 or 1, so they count in binary (base 2). Humans normally use decimal (base 10), and programmers often use hexadecimal (base 16) as a compact way to write binary.

    In any base, each place value is a power of the base. In binary the places, from the right, are worth 1, 2, 4, 8, 16, 32, 64, 128 and so on.

    • Binary to decimal: add the place values where there is a 1. 10112=8+2+1=111011_2 = 8 + 2 + 1 = 11.
    • Decimal to binary: repeatedly divide by 2 and write the remainders from bottom to top, or subtract the largest powers of 2 that fit.
    • Hexadecimal uses the digits 0 to 9 and then A to F for 10 to 15. Each hex digit represents exactly four bits, so to convert between binary and hex, split the binary into groups of four from the right.

    One byte is 8 bits and can hold 256 different values, 0 to 255, which is 00 to FF in hex. That is why colours on the web are written like #FF8000: one byte each for red, green and blue.

    Worked example

    Convert 156 to binary and to hexadecimal.

    1. Powers of 2 that fit: 156=128+16+8+4156 = 128 + 16 + 8 + 4.
    2. Mark the places 128, 64, 32, 16, 8, 4, 2, 1: binary 10011100.
    3. Split into groups of four: 1001 and 1100, which are 9 and 12.
    4. 12 is C in hex, so 156 = 9C.

    Check: 9×16+12=144+12=1569 \times 16 + 12 = 144 + 12 = 156.

    Key facts

    • Place values in binary, from the right: 1, 2, 4, 8, 16, 32, 64, 128. An nn-bit number holds values from 0 to 2n−12^n - 1. For 8 bits that is 255.
    • Place values in hex, from the right: 1, 16, 256. The letters A to F stand for 10, 11, 12, 13, 14 and 15.
    • One hex digit is four bits. Convert in groups of four, starting from the right.

    Worked example 2

    Convert decimal 205 to binary and then to hexadecimal.

    Subtraction method

    1. The largest power of 2 that fits is 128. 205−128=77205 - 128 = 77.
    2. 64 fits. 77−64=1377 - 64 = 13.
    3. 32 and 16 do not fit. 8 fits: 13−8=513 - 8 = 5. 4 fits: 5−4=15 - 4 = 1. 2 does not fit. 1 fits: 1−1=01 - 1 = 0.
    4. Put a 1 under 128, 64, 8, 4 and 1 and a 0 under the rest: 11001101.

    Hex

    1. Split into groups of four: 1100 and 1101.
    2. 1100 is 12, which is C. 1101 is 13, which is D.
    3. So 205 = CD in hex.

    Check: 12×16+13=192+13=20512 \times 16 + 13 = 192 + 13 = 205.

    Worked example 3

    Convert the hexadecimal number 3AF to decimal and to binary.

    1. The places are 256, 16 and 1. A is 10 and F is 15.
    2. 3×256+10×16+15×1=768+160+15=9433 \times 256 + 10 \times 16 + 15 \times 1 = 768 + 160 + 15 = 943.
    3. In binary, 3 is 0011, A is 1010 and F is 1111.
    4. So 3AF is 0011 1010 1111, or 1110101111 without the leading zeros.

    The practice questions on this page use binary numbers of 4 to 6 bits for direct conversion (up to 8 bits in the sums), two-digit and three-digit hex, and ask for the decimal value, not for the base itself. They also ask for sums and for counts of 1 bits.

    Worked example 4

    Add the decimal values of the binary number 10110 and the hex number 1F. Then count the 1 bits in the 8-bit binary form of the hex number B6.

    The sum

    1. 101102=16+4+2=2210110_2 = 16 + 4 + 2 = 22.
    2. 1F16=1×16+15=311\text{F}_{16} = 1 \times 16 + 15 = 31.
    3. 22+31=5322 + 31 = 53.

    The 1 bits

    1. B is 11, which is 1011. 6 is 0110.
    2. B6 is 1011 0110 in binary.
    3. Counting the 1s: three in the first group and two in the second, so 5.

    Common mistakes

    • Adding numbers in different bases directly. Convert each to decimal first, then add.
    • Writing the remainders of repeated division top to bottom. They go bottom to top.
    • Treating the letters as places. In hex, a letter is a digit value, not a place. E is 14, not 5.
    • Forgetting leading zeros in a group of four. 3 is 0011 in a hex conversion, not 11.
    • Grouping from the left. Always group in fours from the right, and pad the left end with zeros.

    Exam tips

    • Write the place values above the bits before you add. It prevents the most common slips.
    • Check any hex answer by converting back, as in examples 2 and 3.
    • Learn 0 to 15 in binary (0000 to 1111). It makes every hex conversion fast.
    • Show the sum as 128+64+8+4+1128 + 64 + 8 + 4 + 1 rather than only the answer. A wrong final number can still earn method marks.
    • If asked for an 8-bit answer, give all 8 bits, including leading zeros.

    What you will practise

    New numbers every time you practise. Levels: Easy, Medium, Hard. Each answer is followed by a worked explanation.

    Example questions

    • Easy

      What is the decimal value of the binary number 11011?

    • Medium

      What is the decimal value of the hexadecimal number 4F?

    • Hard

      Add the decimal value of the binary number 10011010 to the decimal value of the hexadecimal number EE. What is the total?