Class 1 (Lecture notes)
Class 1 (Lecture notes)
Binary systems
and hexadecimal
128 64 32 16 8 4 2 1
27 26 25 24 23 22 21 20
In Denary system is a base 10 system, it uses 0 to 9 values, it counts in multiples of 10 which give us
the well-known headings of units, 10s, 100s, 1000s and so on, It has units/ placeholders/column
headings that increase by the power of 10.
Each time a 1 appears in a column, the column value is added to the total and the 0 values are ignored.
This method involves placing 1s in the appropriate position so that the total equates to the denary
value.
(Note: the maximum denary value of a binary value that consists of n digits, is = (2^n)-1
Example: 1111 1111 (8 digits) àmax value is (27+26+25+24+23+22+21+20= 255=28-1=256-1)
This method involves successive division by 2. The remainders arc then read from BOTTOM to TOP
to give the binary value.
107/2
=53/2 Remainder =1
=26/2 Remainder =1
=13/2 Remainder =0
=6/2 Remainder =1
=3/2 Remainder =0 Read the remainder from bottom to top to
=1/2 Remainder =1 get the binary value: 0 1 1 0 1 0 1 1
=0/2 Remainder =1
0 Remainder =0
Example use of binary
An 8-bit register is used to control the movement of the robot vacuum cleaner:
1 0 1 0 1 0 1 0
Motor B Motor B Motor C Motor C B direction B direction C direction C direction
ON OFF ON OFF Forward Backward Forward Backward
1 1 1 1
Motor B Motor C B direction C direction
ON ON Forward Forward
i) What would be the effect if the register contained the following values 1 0 0 1 1 0 0 0
1 0 0 1 1 0 0 0
Motor B Motor B Motor C Motor C B direction B direction C direction C direction
ON OFF ON OFF Forward Backward Forward Backward
Moto B is On and moving in the forward direction, while motor C is off and doesn’t move at all.
ii) What would the register contain if only motor C was ON and the motors were turning in a
BACKWARDS direction?
iii) What would the register contain if motor B and motor C were both ON but B was turning in a
backward direction and C was turning in a forward direction?
iv) What would be the effect if the register contained the following 11111111?
2 terabyte Hard disc = 2* (1024*1024 MB) = 2* (1,048,576 MB) =2,097,15 MB, means they can
store about half a million 4 MB photos (524,288 * 4MB)
OL Computer science 5 Nepal Ammer
The hexadecimal system
In Hexadecimal system (base 16 à uses from 0 to 9 and letters from A to F = 16 values), it counts in
multiples of 16 (164 =65,536 163 = 4,096 162=256 161=16 160=1)
Binary
Denary Hexadecimal 3 2
2 =8 2 =4 21= 2 20= 1
0 0 0 0 0 0
1 1 0 0 0 1
2 2 0 0 1 0
3 3 0 0 1 1
4 4 0 1 0 0
5 5 0 1 0 1
6 6 0 1 1 0
7 7 0 1 1 1
8 8 1 0 0 0
9 9 1 0 0 1
10 A 1 0 1 0
11 B 1 0 1 1
12 C 1 1 0 0
13 D 1 1 0 1
14 E 1 1 1 0
15 F 1 1 1 1
Converting from binary to hexadecimal is done by starting from the right and moving left, split the
binary number into groups of 4 bits. If the last group has less than 4 bits, then simply fill in with 0s
from the left.
8 4 2 1 8 4 2 1 8 4 2 1 8 4 2 1 8 4 2 1
0 4+2=6 4+2+1= 7 8+2=10=A 8+4+2=14=E
Converting from hexadecimal to binary is done by taking each hexadecimal digit and write down the
4-bit code which corresponds to the digit
B= 11 F=15 0 8
3
2 2 2 2 2 2 2 2 2 2 2 2 2 2 21 20
2 1 0 3 2 1 0 3 2 1 0 3 2
8 4 2 1 8 4 2 1 8 4 2 1 8 4 2 1
1 0 1 1 1 1 1 1 0 0 0 0 1 0 0 0
To convert a hexadecimal number to denary, take each hexadecimal digit and multiply it by its value .
Add the totals together to obtain the denary value.
To convert from denary to hexadecimal we’ll use the same methods used to convert from Denary to
Binary:
This method involves placing a value in the appropriate position so that the total equates to the
denary value.
This method involves successive division by 16. The remainders arc then read from BOTTOM to TOP
to give the hexadecimal value.
2004/16
=125/16 Remainder =4 Read the remainder from bottom to top to
=7/16 Remainder =13=D get the hexadecimal value: 7 D 4
=0 Remainder =7
Note:
To convert from hexadecimal to denary; you can convert from Hexadecimal to binary and from binary
to denary, you can do the same for the conversion from denary to hexadecimal (denary à binary à
hexadecimal)