Course 1.1Lesson 1 of 3
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.
Try the code and the simulations beside the lesson.
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.
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 the digit 4 is worth .
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.
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).
Write the place values above the bits. Then add up the place values that have a 1 under them.
Convert 01101001 to denary.
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: . So 8 bits hold the numbers 0 to 255, which is 256 different values.
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.
So 77 is 01001101. Check: .
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.
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.
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: . So the answer is 0000001111101000. It helps to write it in groups of four: 0000 0011 1110 1000.
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.
// 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 PositionThe Python program below does the same job, so you can watch it work. In Python, // is DIV and % is MOD.
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.
Try each one on your own first. If you are stuck, open a hint. Then check with Show the answer.
Every lesson is open to read. Enrolling also lets you:
Log in to join the discussion.
Loading…
This lesson is free to read. Enroll free to keep your place and take the tests.