You are on page 1of 4

Computer Science

Teacher: Maruf Ahmed


Chapter 1 (Data representation)
Signed and Unsigned numbers, binary addition and logical shift

In O’ level syllabus, only integer (whole number) calculation is included.


There are three numbering system that you need to be familiar with. They are:
- Binary - is a base 2 system where the distinct digits are 0 and 1. The value gets increased by
multiple of 2 to the left hand side. The right most bit will have a multiple of 20 and will keep
growing as 21, 22 and so on. So the place value for each digit from right to left will be 1, 2, 4 and
so on.
- Denary - is a base10 system where the distinct digits are 0 to 9. The value gets increased by
multiple of 10 to the left hand side. The right most digit will have a multiple of 100 and will keep
growing as 101, 102 and so on. So the place value for each digit from right to left will be 1, 10,
100 and so on.
- Hexadecimal - is a base16 system where the distinct digits are (0 to 9 and A to F). The value gets
increased by multiple of 16 to the left hand side. The right most digit will have a multiple of 160
and will keep growing as 161, 162 and so on. So the place value for each digit from right to left
will be 1, 16, 256 and so on.

You need to know the process to convert from one number system to another number system
- Denary to Binary
- Binary to Denary
- Binary to Hexadecimal
- Hexadecimal to Binary
- Denary to Hexadecimal
- Hexadecimal to Denary

Denary to Binary:
Process 1:
- Use successive division by 2 and get the remainder until quotient becomes 0.
- Then from the bottom, pick the remainder up the order and place them from left to right.
- Then fill up the number of bits as per the question required. Suppose a result for a denary numer
has appeared in 6 bits and in the question it is given to represent in 8 bits, then add two 0s to the
left.
Process 2:
- Write down the place value (using multiple of 2, which starts 20 from right) for each binary
number from right to left such as 1, 2, 4, 8, 16, 32, 64 etc. depending on the value that you are
looking for
- Place 1 below each of the place value and add them up to make the value you are looking for

Binary to Denary:
- Write down the place value (using multiple of 2, which starts 20 from right) for each binary
number from right to left such as 1, 2, 4, 8, 16, 32, 64 etc.
- Add up all the place values for each 1’s and the result is the denary number of the binary number

Page 1 of 4
Binary to Hexadecimal:
- Starting from the right hand side, make groups of 4 bits. That means each group will have exactly
4 bits
- If the last group has less than 4 bits, then add 0s to the left to make group of 4 bits
- For each group, get the equivalent denary number
- Replace the hexadecimal digit for each denary number
- Put the values together
Hexadecimal to Binary
- Convert each hexadecimal digit to equivalent 4 bits number
- Put the values together
Denary to Hexadecimal
- The process is known as successive division by 16.
- However you have to go for long division and get the integer remainder. The first remainder will
be the right most hexadecimal digit.
- Then go for long division again for the left over quotient. Using long division, divide the number
by 16 again and get the integer remainder. It will become second digit from the right.
- In this way continue the long division by 16 until the quotient becomes 0.
Hexadecimal to Denary
- Use the place value (multiple of 16, which starts with 160) for each hexadecimal digit from the
right hand side
- Multiply the hexadecimal digit with the place value
- Add up the values together

Unsigned number and signed number:


Unsigned number means that no bit has been assigned as sign bit. Every number is a positive number.
Signed number means that the Most Significant Bit (MSB) is the sign bit and it can be both positive and
negative numbers. In this case the method that is used to calculate a number is called two’s complement
method. If the MSB is 1 then it is going to be a negative number and if the MSB is 0 then it is going to be
a positive number.
Number of values that can be represented in n bits in unsigned form is:
2n where n = number of bits. That means if n is 8 then 28 = 256 different values can be represented in 8
bit
Range of values that can be represented in n bits unsigned form in denary
(0 to 2n – 1)
If n = 8 then the range of values that can be represented is (0 to 28 – 1) which means 0 to 255. This means
the lowest denary value in 8 bit is 0 and the highest denary value is 255.
So we can say that in 8 bit representation the lowest number that can be represented in binary is
00000000
And the highest number that can be represented in 8 bit binary is
11111111

In signed number method, MSB is the sign bit.


- MSB: Most significant bit is the bit which is the farthest left bit. If the MSB is 0 (zero) then it
means the number is a positive number and if the MSB is 1 then the number is a negative number
- LSB: Least significant bit is the bit which is the farthest right bit

Page 2 of 4
Two’s complement method:
This is applicable for binary to denary and denary to binary.
Both positive and negative numbers can be represented in Two’s complement method.

Process of conversion of positive denary number into binary number in Two’s complement:
- It is the same as normal denary to binary representation where the MSB will definitely be a 0
(zero)

Process of conversion of negative denary number into binary number


- write down the binary representation for the equivalent positive denary number following the
number of bits that is mentioned
- Invert (flip) / toggle every bit (this is known as one’s complement). Every 1 becomes 0 and every
0 becomes 1
- Add 1 to this using binary addition and the result is the representation in two’s complement
- In two’s complement representation of a negative denary number in binary, the MSB will
definitely be 1

Process of converting a binary number into denary which is represented in Two’s complement method
and which starts with 0 (zero)
- Since the MSB is 0 (zero), just add the place values for the bits which are having 1

Method 1 when the MSB is 1 (You can use this method when you do not need to show your
working):
- place value for the MSB will be negative place value and the rest of the bits will be having
positive place values
- Add up the place values for each 1’s including the MSB place value (which will be negative). The
result will be a negative denary number

Method 2 when the MSB is 1 (You have to use this method when it is written to show your
working):
- Invert (flip) / toggle every bit (This is known as one’s complement). Every 1 becomes 0 and every
0 becomes 1
- Add 1 to this using binary addition and the result is the representation in two’s complement of the
negative number
- Since the number started with 1 that is why it will be a negative representation of the denary
number

Range of values that can be represented in two’s complement method:


-(2n-1) to + (2n-1 -1)
If n = 8 then the range will be -128 to +127 in denary which means 256 different values can be
represented in 8 bit. So, (-128) is the lowest denary value and (+127) is the highest denary value in 8 bit.
So we can say that in 8 bit representation the lowest number that can be represented in binary is
10000000
And the highest number that can be represented in 8 bit binary is
01111111

Page 3 of 4
Addition of binary numbers:
The following rules are used
Addition of bits Sum Carry
0+0 0 0
0+1 1 0
1+0 1 0
1+1 0 1
1+1+1 1 1

This is to be noted that you are normally asked to show your working for binary addition. In that case you
must show sum and carry part (carry of 1’s) clearly. Binary addition will be given only for positive
numbers.

What is overflow and how does it occur?


A condition when the result of a calculation is too large to fit into the number of bits defined for storage.
Binary addition is said to overflow if the result is too big to fit in the available bits. When two binary
number addition results more than the capacity of the storage unit size then this is called overflow.
An overflow error occurs when a value outside the limit is calculated. For example the highest value for
an eight bit register is 255. If the addition of two 8 bit binary numbers gives the result more than 255 then
the result of the addition cannot be accommodated in that register and overflow will occur. For example
in eight bit registers, denary 120 and 140 will result as 260 which cannot be accommodated in eight bit
register. But you have to show the overflow bit in calculation if there is any.

Logical shifting:
Logical shifting in binary: means shifting the position of bits to the left or to the right. There are two
types of logical shift. Logical shift left and Logical shift right.

Logical shift left: Bits from the right (LSB) starts to shift its position and moves towards left. For each
left shift the value from the left (MSB) of a register drops off and since the right most bit (LSB) gets
empty that is why the LSB will be filled up with 0 (zero) no matter what value has been dropped off.
Effect of left shift: The value gets multiplied by 2 for each left shift usually. That means if there is a left
shift of 2 bits then the value will be multiplied by 4.
Exception: Since the register size is fixed, so when there is a loss of a bit of 1 to the left side then the
result will be different which means the multiplication pattern will not be followed. It will be a different
value which should be mentioned.

Logical shift right: Bits from the left (MSB) starts to shift its position and moves towards right. For each
right shift the value from the right (LSB) of a register drops off and since the left most bit (MSB) gets
empty that is why the MSB will be filled up with 0 (zero) no matter what value has been dropped off.
Effect of right shift: The value gets divided by 2 for each right shift usually. That means if there is a
right shift of 2 bits then the value will be divided by 4.
Exception: Since the register size is fixed, so when there is a loss of a bit of 1 to the right side then the
result will be different which means the division pattern will not be followed. In this case there will be
loss of precision (accuracy) which means fraction of values will be lost as it will be mentioned that the
register could only hold onto integer values.

Page 4 of 4

You might also like