Teach Computer
Science
Binary system
teachcomputerscience.co
m
1
.
Revision notes
teachcomputerscience.co
m
Introduction
A computer has many electronic components that work as
switches. These components have two logics as input and
output: ON and OFF. A similar logic is used to represent data in
binary form. ON is represented as 1 and OFF is represented as
0.
Place value of denary
system
The denary system has a base value of 10. It counts in
multiples of 10. The number 7324 has 7 thousands, 3
hundreds, 2 tens and 4 ones. The following figure illustrates the
place values in a denary system.
Figure 1: Place values in a denary system
teachcomputerscience.co
m
Place value of binary
system
The binary numbers can also be represented using place
values. The place values have a base 2. The first 8 digits are
represented in the table below.
12
64 32 16 8 4 2 1
8
In the figure below, the denary number 24 is converted to
binary.
Figure 2: Binary equivalent of 24
In the figure below, the denary number 43 is converted to
binary.
Figure 3: Binary equivalent of 43
teachcomputerscience.co
m
Size of computer memory
A binary digit is referred to as a bit. A nibble consists of 4 bits.
A byte consists of 8 bits. A byte is the smallest unit of memory
of the computer system. The memory sizes available with
computers are in multiples of 8 such as 16-bit systems, 32-bit
systems, etc.
The memory sizes were originally standardised as using the
base-2 representation. In this system, the prefixes kibi-, mebi-,
gibi-, tebi- are used to avoid conflicts with base-10 system.
New name of the Number
Equivalent to
memory size of bytes
1 kibibyte (1 kiB) 1024 bytes
1 mebibyte (1
10242 bytes
MiB)
1 gibibyte (1
10243 bytes
GiB)
1 tebibyte (1 TiB) 10244 bytes
This representation is now used for representing the size of
RAM modules only. After the standardisation of base-10
representation, the memory sizes are now represented as:
Name of the Number
Equivalent to
memory size of bytes
1 kilobyte (1 kB) 1000 bytes
1 megabyte (1 1000000 bytes or
MB) 1000 kB
1 gigabyte (1
1000 MB
GB)
1 terabyte (1 TB) 1000 GB
1 petabyte (1
1000 TB
PB)
teachcomputerscience.co
m
Converting denary to binary
A denary number is converted to binary by dividing it by 2 and
calculating the remainders as shown in the following example. Let us
convert 91 to a binary number.
Figure 3: Converting denary number 91 to binary
The binary equivalent of the denary number 91 is obtained by arranging
the remainders in reverse order.
0 1 0 1 1 0 1 1
The answer can be checked by:
91
teachcomputerscience.co
m
Binary combinations
Audio files use bit depth to denote the number of bits of information in
each sample. A one-bit system has one-place value and can have 2
possible combinations: 0 or 1.
Similarly, a 2-bit system has two-place values and has 4 possible
combinations, as shown in the table below:
Place value Place value Binary Denary
2 1 number number
0 0 00 0
0 1 01 1
1 0 10 2
1 1 11 3
Similarly, a 3-bit system has three-place values and has 8
possible combinations, as shown in the table below:
Place Place Place Binary Denary
value 3 value 2 value 1 number number
0 0 0 000 0
0 0 1 001 1
0 1 0 010 2
0 1 1 011 3
1 0 0 100 4
1 0 1 101 5
1 1 0 110 6
1 1 1 111 7
From the above examples, it can be noted that an n-bit system
has 2n possible combinations.
teachcomputerscience.co
m
Representing numbers
Programmers use many arithmetic operations in a program.
The numbers are either represented as integers or floating
point numbers. Integers are whole numbers and floating point
numbers are used to represent numbers with decimal points. A
16-bit system can represent integers up to 216-1=65535. 8-bit,
16-bit, 32-bit and 64-bit are the most common bit lengths.
Adding binary numbers
Binary numbers are added in a column method as the denary
numbers are added. Let us consider the following example of
adding 0101 and 1011.
Place value Place value Place value Place value
4 2 3 1
Carry 1
Number 1 0 1 0 1
Number 2 1 0 0 1
Sum 1 1 1 0
When the binary digits 1 and 0 are added, the sum is 1. When
both the digits are 0, the sum is 0. When both the digits are 1,
the sum is 10 and 1 is carried over. 0101 and 1001 represent
the denary numbers 5 and 9. The sum of 5 and 9 is 14. Convert
the sum obtained to denary number.
(8×1)+(4×1)+(2×1)+(0×1)=14
teachcomputerscience.co
m
Another example:
Place Place Place Place
value 4 value 2 value 3 value 1
Carry 1 1
Number
1 1 0 1
1
Number
1 1 0 1
2
Sum 1 1 0 1 0
The rules are:
1 + 0 = sum 1 and carry 0
1 + 1 = sum 0 and carry 1
1 + 1 + (carry 1) = sum 1 and carry 1
Adding three 1’s results in a sum of 1 and a carry of 1.
Similarly, three binary numbers can be added.
Place Place Place Place
value value value value
4 2 3 1
Carry 1 1 1
Numb
1 1 0 1
er 1
Numb
1 0 0 1
er 2
Numb
1 1 1 1
er 3
Sum 1 0 0 1 0 1
The rules are:
1 + 0 + 0 = sum 1 and carry 0
1 + 1 + 0 = sum 0 and carry 1
1 + 1 + 1 = sum 1 and carry 1
1 + 1 + 1 + (Carry 1) = 1 0 0
Adding four 1’s results in a sum of 0 and carry 1 is placed two
places to the left.
teachcomputerscience.co
m
Overflow Error
A CPU with an 8-bit register has a capacity of up to 11111111
in binary. If an extra bit is added, it is said to be an overflow
error. Consider addition of two binary numbers 11101101 and
10000100 as shown below:
Carr 1 1 1
y
Num 1 1 1 0 1 1 0 1
ber
1
Num 1 0 0 0 0 1 0 0
ber
2
1 0 1 1 1 0 0 0 1
Sum
The sum of these two numbers is bigger than 8 bits (an extra
bit than the register can hold). The computer thinks that
11101101+10000100=01110001 as it does not have space to
store the extra bit. The number of bits a register can hold is
called word size. Exceeding the capacity of word size in a
register results in an overflow error.
teachcomputerscience.co
m
Binary shifts
Let us consider the denary number 6. Its binary equivalent is
0110.
Denary
number
6 0 0 0 0 0 1 1 0
The binary equivalent of 12 (6 × 2) is:
Denary
number
12 0 0 0 0 1 1 0 0
It can be noted that the binary equivalent of 6 shifted to the
left is the binary equivalent of 12. Now, the binary equivalent of
24 is:Denary
number
24 0 0 0 1 1 0 0 0
Again, it can be noted that the binary equivalent of 12 shifted
to the left is the binary equivalent of 24. It can be summarised
that when a denary number is multiplied by 2, its binary
equivalent shifts left by 1 place. Also, multiplication by 4 results
in the shift of the binary equivalent by 2 places and
multiplication by 8 results in a shift of the binary equivalent by
3 places and so on.
teachcomputerscience.co
m
Representing negative
numbers
Signed integers can be either positive or negative. An extra bit
is used to represent the sign of a number in binary
representation. In case of signed numbers, the leftmost bit is
used to represent sign and is called the sign bit. 0 represents a
positive number and 1 represents a negative number. The rest
of the bits represent the magnitude of the number. Consider
the 8-bit binary number 10001101.
Sign
Magnitude
bit
1 0 0 0 1 1 0 1
Binary
Denar -13
y
The smallest number that can be represented using 8 bits is
11111111 (-127) and the largest number is 01111111 (+127).
Similarly, the signed number can be represented in 32-bits, 64-
bits and so on.
Finding two’s complement is an alternate method to represent
negative numbers. This method is used by most computers to
perform mathematical operations.
Let us consider an example of representing -5. The binary value
of 5 is 101. The leftmost bit is added to represent the positive
sign. +5 is 0101. Each bit is inverted and, hence, the 0101
becomes 1010. 1 is added to this number. 1010 + 1=1011. A
few examples of representing binary numbers using two’s
complement are given in the table below:
Sign bit
(23) (22) (21) Denary
(-23)
number
1 0 1 1 -5
0 1 1 1 7
1 0 0 1 -7
1 1 0 1 -3
teachcomputerscience.co
m
Sum of numbers: Using
two’s complement
Let us consider adding -4 and 3 using two’s complement.
Sign bit
(23) (22) (21)
(-23)
Carry
Number 1 = - 1 1 0 0
4
Number 2 = 0 0 1 1
3
Sum 1 1 1 1
Converting the sum 1111 into denary number,
-8+4+2+1=-1
teachcomputerscience.co
m
Applications of binary
system
Microprocessors in computer use register to control devices
such as robots. Registers store a group of bits.
Let us consider a robotic vehicle that has four wheels. The two
wheels in the front helps us to change the direction of motion
in four ways (front, back, left and right). The two wheels in the
back simply revolves either in forward or backward direction.
An electric motor is attached to C and D.
A D
Front Wheels Back Wheels
(rotates freely) (Attached to
B C
motor)
A register used to control this robotic vehicle is:
Motor C Motor D Wheel C Wheel D
ON OFF ON OFF Front Back Front Back
1 0 1 0 0 1 0 1
For example: A value of 10100101 means ‘ Motor C is ON and
Motor D is ON and both wheels are moving together
backwards.’ As a result of these values, the robotic vehicle
moves backwards.
teachcomputerscience.co
m
2
.
Activities
teachcomputerscience.co
m
Activity-1
Duration: 15 minutes
1. Find the binary equivalent of the denary number 113.
2. Check your answer by using the appropriate place values.
teachcomputerscience.co
m
Activity-2
Duration: 15 minutes
1. What is the binary equivalent of the denary numbers 11
and 14. Show your working in the box below.
2. Add the two binary numbers obtained in question 1. Show
your working in the box below.
3. Find the denary equivalent of the sum obtained in question
2. Show your working in the box below.
teachcomputerscience.co
m
Activity-3
Duration: 15 minutes
1. This activity is about application of binary system. Consider
a device with four motors and a register in a
microprocessor that controls this device.
A D
Front Wheels Back Wheels
(rotates freely) (Attached to
B C motor)
Motor C Motor D Wheel C Wheel D
ON OFF ON OFF Front Back Front Back
a) What happens if the register consists of 10010100?
b) What values would the register consist of if both the motors
(C & D) are ON, but wheel C moves in backward direction
and wheel D moves in forward direction? What effects does
this value have on the device?
teachcomputerscience.co
m
2
.
End of topic
questions
teachcomputerscience.co
m
End of topic questions
1. Convert the following denary numbers to binary.
a) 13
b) 52
c) 145
2. Convert the following binary numbers to denary.
a) 1010
b) 111000
c) 11110111
3. How many megabytes are there in 3 terabytes?
4. Add the following binary numbers. Show the necessary
working.
a) 1011 + 1001
b) 10110110 + 1010 0011
5. Add the following binary numbers. Show the necessary
working.
a) 1010 + 0011 + 1101
b) 10101010+ 0010 1011 + 0010 1001
6. Draw a robotic vehicle controlled by a microprocessor and
label the motors and wheels. Explain briefly how the robotic
vehicle moves in all four directions (frontwards, backwards,
towards left and towards right).
teachcomputerscience.co
m