HelpContactFor teachers and institutes
>_StemPy Lab
Mock TestsClasses

>_StemPy Lab

Learn. Solve. Code the solutions. Test yourself.

Live examsFree mock exams, timed and rankedEveryone starts together, and your score and rank come the moment it ends.See the exams →

Learn

  • Physics
  • Chemistry
  • Mathematics
  • Biology
  • Python Programming
  • Statistics & Data Science
  • Computer Science
  • Classes
  • Groups

Practice

  • Problems
  • Quizzes
  • Mock Tests
  • Prepare for an Exam
  • Question Sets
  • Exams
  • Certificates
  • Python Labs
  • AI Practice Generator
  • Student-Created Tests

Community

  • Discussions
  • Resources
  • Notes
  • Glossary
  • Blog

Account

  • Log in
© 2026 senLearn. All rights reserved.HelpFor SchoolsAboutContactPrivacy PolicyTerms of UseRefund Policy
Binary, Denary and Hexadecimal
  1. 1Binary and denary
  2. 2Hexadecimal and why we use it
  3. 3Binary addition, overflow, shifts and two's complement
  1. Computer Science
  2. /Binary, Denary and Hexadecimal
  3. /Binary and denary

Course 1.1·Lesson 1 of 3

Binary and denary

A computer stores and processes every kind of data as binary, a number system with only the digits 0 and 1. You learn why, read the place values of binary, and convert between binary and denary in both directions, for numbers of up to 16 bits.

about 30 min1 simulation1 practice question
Lesson 1 of 3Show all lessonsHide
Binary, Denary and Hexadecimal
  1. 1Binary and denary
  2. 2Hexadecimal and why we use it
  3. 3Binary addition, overflow, shifts and two's complement

Try the code and the simulations beside the lesson.

Why a computer uses binary

Think of a light switch. It has two states: on and off. A computer is built from millions of tiny electronic switches. Each one is either on or off, so each one can store one of two digits: 1 for on and 0 for off.

A number system with only two digits is called binary. Every kind of data, such as numbers, text, sound and pictures, must be turned into binary before a computer can process it. The data is processed by logic gates and kept in registers, which are small stores inside the processor. Both work with 1s and 0s.

One binary digit is called a bit. A group of 8 bits is a byte.

Denary and binary

You already count in denary, the base 10 system. It has ten digits, 0 to 9. Each place is worth ten times the place to its right: units, tens, hundreds, thousands. In 472472472 the digit 4 is worth 4×1004 \times 1004×100.

Binary is the base 2 system. Each place is worth two times the place to its right. An 8-bit binary number has these place values, from left to right.

  • 128, 64, 32, 16, 8, 4, 2, 1
Eight boxes in a row, one for each bit of a byte. Above them, from left to right, are the place values 128, 64, 32, 16, 8, 4, 2 and 1. The boxes hold the bits 0, 1, 1, 0, 1, 0, 0, 1. The leftmost box is labelled most significant bit and the rightmost box least significant bit. Under the row the sum 64 + 32 + 8 + 1 = 105 is written.

The leftmost bit has the largest place value. It is called the most significant bit (MSB). The rightmost bit, worth 1, is the least significant bit (LSB).

Binary to denary

Write the place values above the bits. Then add up the place values that have a 1 under them.

Convert 01101001 to denary.

  1. The 1s are under 64, 32, 8 and 1.
  2. Add them. 64+32+8+1=10564 + 32 + 8 + 1 = 10564+32+8+1=105.

So 01101001 in binary is 105 in denary. The 0 at the front does not change the value, but an 8-bit register always shows all eight bits.

What is the largest number that 8 bits can hold? Set every bit to 1: 128+64+32+16+8+4+2+1=255128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 = 255128+64+32+16+8+4+2+1=255. So 8 bits hold the numbers 0 to 255, which is 256 different values.

Denary to binary

There are two methods. Use the one you find easier, and check with the other.

Method 1: take away place values. Start at 128. If the place value fits into what is left, write 1 and take it away. If not, write 0. Move to the next place value.

Convert 77 to 8-bit binary.

  1. 128 does not fit into 77, so the first bit is 0. 64 fits: write 1, and 77−64=1377 - 64 = 1377−64=13 is left.
  2. 32 and 16 do not fit into 13: write 0 and 0.
  3. 8 fits: write 1, and 13−8=513 - 8 = 513−8=5 is left. 4 fits: write 1, and 1 is left.
  4. 2 does not fit: write 0. 1 fits: write 1.

So 77 is 01001101. Check: 64+8+4+1=7764 + 8 + 4 + 1 = 7764+8+4+1=77.

Method 2: divide by 2 again and again. Divide by 2 and write down the remainder. Divide the answer by 2 again. Stop when you reach 0. Then read the remainders from the bottom up.

Repeated division of 77 by 2, one line per step: 77 divided by 2 is 38 remainder 1, 38 is 19 remainder 0, 19 is 9 remainder 1, 9 is 4 remainder 1, 4 is 2 remainder 0, 2 is 1 remainder 0, and 1 is 0 remainder 1. An arrow beside the remainders points upwards, to show that they are read from the bottom up as 1001101.

The picture divides 77 by 2 again and again. The remainders, read from the bottom up, are 1001101. Add a 0 at the front to make 8 bits: 01001101, the same as before.

Up to 16 bits

The syllabus uses binary numbers of up to 16 bits. The place values keep doubling to the left: 256, 512, 1024, 2048, 4096, 8192, 16384 and 32768. A 16-bit number can hold values from 0 to 65535.

Convert 1000 to 16-bit binary. Take away place values: 1000=512+256+128+64+32+81000 = 512 + 256 + 128 + 64 + 32 + 81000=512+256+128+64+32+8. So the answer is 0000001111101000. It helps to write it in groups of four: 0000 0011 1110 1000.

The same idea in pseudocode

The examination writes algorithms in pseudocode, a way of writing steps that looks like a program but follows fixed rules. The site cannot run pseudocode, so it is shown in a plain box. DIV gives the whole-number part of a division and MOD gives the remainder. This algorithm stores the eight bits of a number in an array, last bit first.

pseudocode
// Denary to 8-bit binary by repeated division by 2
DECLARE Number : INTEGER
DECLARE Position : INTEGER
DECLARE Bit : ARRAY[1:8] OF INTEGER
INPUT Number
FOR Position ← 8 TO 1 STEP -1
    Bit[Position] ← MOD(Number, 2)
    Number ← DIV(Number, 2)
NEXT Position
FOR Position ← 1 TO 8
    OUTPUT Bit[Position]
NEXT Position

The Python program below does the same job, so you can watch it work. In Python, // is DIV and % is MOD.

Practise with new numbers

Try it in Python

The program turns 77 into binary by repeated division, exactly as the pseudocode does. Then it checks the answer with Python's own int(text, 2), which reads a binary string.

Read it first. Then run it. Do the two lines at the end give the same number?

1. Change number = 77 to number = 200. Predict the 8 bits before you run it.

2. Change it to 300. What goes wrong with only 8 bits?

Common mistakes

  • Reading the remainders the wrong way. In Method 2 the first remainder is the least significant bit. Read from the bottom up.
  • Dropping bits. An 8-bit answer has eight digits. Put 0s at the front if you need them.
  • Mixing up the ends. The leftmost bit is worth the most.
  • Forgetting to check. Add the place values of your answer. You should get the number you started with.

Remember these

  • Binary is base 2, denary is base 10 and hexadecimal is base 16.
  • The 8-bit place values are 128, 64, 32, 16, 8, 4, 2 and 1.
  • 8 bits hold 0 to 255. 16 bits hold 0 to 65535.
  • Binary to denary: add the place values under the 1s.
  • Denary to binary: take away place values, or divide by 2 and read the remainders from the bottom up.

Check yourself

Try each one on your own first. If you are stuck, open a hint. Then check with Show the answer.

  1. Convert the binary number 00101100 to denary.
  1. Convert the denary number 90 to 8-bit binary.
  1. A sensor stores its reading in 16 bits. What is the largest reading it can store?
  1. Give one reason why a computer stores data in binary.
  1. Convert the denary number 300 to 16-bit binary.

Enroll free in Binary, Denary and Hexadecimal

Every lesson is open to read. Enrolling also lets you:

  • Mark lessons done and carry on where you stopped.
  • Take the tests of this lesson and its course.
  • Count the course towards the certificate for its chapter.
No payment. You can leave at any time.

Problems (3)

A games console keeps the number of lives a player has left in one 8-bit register…Easy · High School (9–10) · by StemPy Lab
A school scoreboard shows each score with eight lamps in a row…Medium · High School (9–10) · by StemPy Lab
A car park barrier counts the cars that pass through it in one year, in a 16-bit register…Hard · High School (9–10) · by StemPy Lab
Next: lesson 2Hexadecimal and why we use it
← Binary, Denary and Hexadecimal
← PreviousHexadecimal and why we use it →

Discussion (0)

Log in to join the discussion.

Loading…

1 Python program
5 questions to check yourself

This lesson is free to read. Enroll free to keep your place and take the tests.

Python Labs (1)

Write your own binary converterPython Lab · by StemPy Lab