Topic 3
DATA
Nida Jawad
https://youtu.be/M41M9ATm49M
Number Systems
1) BINARY:
Base 2
(0,1)2
(10101010)2
2) DECIMAL or DENARY:
Base 10
(0 to 9)10
(55)10 (372)10
Number Systems
3) HEXADECIMAL:
Base 16
((0 to 9) and (A to F)) 16
Where A= 10, B=11, C=12, D= 13, E=14 and F=15
(A03)16
Binary is a base-2 numeral system using only two digits: 0 and 1. It is a positional
notation where digits have place values, like the denary or decimal system that we are
familiar with. For example, in the decimal system, each 1 in the number 111 represents
a different value i.e. from left to right they represent 100, 10 and 1.
https://www.youtube.com/watch?v=RrJXLdv1i74
Analog Data Digital Data
• Continuous in nature • Discrete in nature
• Real time signal • Exists in a computer
• Can have multiple values • Can have only two values
Binary is needed to represent data and program instructions because of the way in which
computers work.
The processor, which processes all of the data and instructions, contains billions of
transistors which are connected together to form circuits.
The transistors act as switches, similar to light switches. They have only two states: on
or off; they either transmit an electric current or they do not. A system with separate
states is said to be digital. If there are two states, the system is binary. There are no in-
between states with different levels of current as there would be in a dimmer switch,
which produces different levels of brightness in a bulb. A system such as this, where
there is a continuous range between two values, is said to be analogue.
https://www.quora.com/Why-is-the-transistor-so-crucial-to-computers-and-what-role-does-it-play-in-computing
As there are only two states, on or off, the states are represented by the digits of the
binary number system, 1 and 0. All of the data and program instructions processed by a
computer are nothing more than streams of millions of 1’s and 0’s.
Numbers, text, graphics and sound are all represented in the same way, as a series of
1’s and 0’s. The program instructions that the processor is following allow it to interpret
them in different ways.
There are only two digits: 1 and 0. However, to represent the symbols in text, there
must be at least 52 separate items of information — 26 lower-case and 26 upper-case
letters. Then there are punctuation symbols — the full stops, question marks, etc.
When we write, we combine the letters in our alphabet to create words and combine
these into sentences to express meaning. In a similar way, the two binary digits (bits)
can be combined into groups.
A single bit offers two possibilities. In a graphics program it could give black (1) or white
(0), for example. If we wanted colour, we'd need more combinations. If two bits are used
this gives four possible combinations (00, 01, 10, 11), each of which can represent a
colour; so four colours could be used.
Three bits would give eight combinations, 000, 001, 010, 011, 100, 101, 110, 111,
allowing eight different colours to be represented. With four bits there would be 16
combinations.
There is obviously a mathematical relationship between the number of bits used and the
number of possible colours.
The number of possible colours is equal to 2 to the power of the number of bits used in
the combination.
2 𝑛
Where n represents the number of bits
20= 1
21= 2
22= 2 ∗ 2 = 4
23= 2 ∗ 2 ∗ 2 = 8
24= 2 ∗ 2 ∗ 2 ∗ 2 = 16
Binary is a number system based on two digits, O and 1.
We are more used to the denary system which has ten digits, 0 to 9, but the binary
system functions in the same way. The difference is that the denary system works in
powers of 10, while the binary system uses powers of 2.
Every digit has a place value, and the one to the left has a value 10 times higher than
the one to the right.
This table shows the place values for the digits in the number 3639.
Therefore, 3639 can be written as:
(3 * 1000) + (6 * 100) + (3 * 10) + (9 * 1)
The binary system has similar place values, but they increase by powers of 2.
The table shows the place values for the digits in a byte.
This table can be used to convert a binary number to a denary one.
The denary equivalent of the binary number 10101101 can be calculated as
shown in the table below:
(1 *128) + (1 *32) + (1*8) + (1*4) + (1*1) = 128 + 32 + 8 + 4 + 1 = (173)10
Binary numbers can be manipulated in the same way as denary ones.
DENARY ADDITION
When addition is performed in denary, a 'carry over' is used if the result is
greater than 9.
BINARY ADDITION
Binary addition works in the same way, but a 'carry over' is needed if the result is
greater than 1.
We are adding 8-bit numbers, and this has caused a problem. All 8 bits have been used
and the 1 that was carried over in the last column has nowhere to go — it has been
'carried out'. Therefore, the result of the calculation would be wrong. This is called an
overflow error.
This condition occurs when a calculation produces a result that is greater than the
computer can deal with or store. When this happens, the processor is informed that an
error has occurred.
So far, we have been considering whole numbers or integers that are positive, but how
can we represent negative numbers? When an integer is indicated as being positive or
negative, it is described as being signed.
In denary, this is simple, a '+' or a '—' symbol is placed in front of the number. If we are
using 8-bit numbers in binary, we cannot do this because we cannot simply add an extra
bit. Also, the processor would not understand the '+' and — symbols.
SIGN AND MAGNITUDE
In a multiple-bit binary number, the left-most bit (the one with the greatest value) is
called the most significant bit (MSB). We can use this to represent signed integers. It is
set to 1 for negative and 0 for positive.
Therefore, using this method, binary 00011100 represents denary +28 and binary
10011100 represents —28 The most significant bit is being used for the sign, so the
largest positive number represented by a byte is 127.
If the binary equivalents of denary +28 and denary —28 are added, we get the following
result.
Adding denary +28 and —28 we expect the result to be 0, but the binary result is
equivalent to —56.
Also using this method, 0 could be both positive and negative.
That clearly doesn't make sense and so another method is needed to represent negative
numbers in calculations.
The most common method used to represent signed integers in modern computers is
two's complement. This is a method of representing binary numbers to show whether
they are positive or negative. This method works on the principle above - the result of
any number added to its negative equivalent should be 0.
FINDING THE TWO'S COMPLEMENT OF A BINARY NUMBER
To find the two's complement of a binary number:
flip all of the bits — change 1’s to 0’s and 0’s to 1’s
add 1 to the result.
CONVERTING TWO'S COMPLEMENT NUMBERS BACK INTO DENARY
This example shows that the two's complement binary number 1 1100100 represents
denary —28. We can check whether this statement is true by converting it back from
two's complement.
METHOD 1 - REVERSE CALCULATION
The positive equivalent of a negative integer in two's complement format can be found
by flipping the bits and adding 1.
The result is denary 28.
This shows that 11100100 (—28) is the two's complement representation of 00011100
(+28).
METHOD 2 - PLACE VALUES
Using place values, the two's complement number can be converted directly into denary.
The MSB of the two's complement binary number is 1 , indicating that it is negative.
Therefore, the denary equivalent of the MSB is taken as being negative —128.
The denary equivalent will be
—128 + 64 + 32 + 4 = — 128 + 100 = -28
This shows that two's complement 1 1 100100 is equivalent to denary —28.
ADDING -28 TO +28
The two's complement of 00011100 is 1 1100100.
So, adding the binary equivalents of denary +28 and —28 gives:
There is an overflow, but this time the result is 0.
In denary, when we want to multiply a number by 10, we move each
number one place value to its left and add a 0 to the end. For example,
13 * 10 = 130.
To divide by 10, we do the reverse — move each number one place
value to its right.
A left shift is used for multiplication by 10 and a right shift for division
by 10.
If the number is being multiplied by 100 (102), then each digit is moved
two places to its left.
In binary left and right, binary shifts can be used for multiplication and
division by powers of 2.
LOGICAL SHIFTS
For unsigned numbers, logical shifts are performed in the same way as
in denary.
If we multiply the unsigned binary number 00010100 (20) by 22 (4),
there should be two shifts to the left.
The left-most bits drop off the end and are replaced by 0’s at the right.
The product is (64 * 1) + (16 * 1) = 80 in denary as expected.
If we divide the same number by 4 (22), there would be two shifts to
the right.
This time the right-most bits drop off the end and are replaced by Os at
the left.
The result is (4 * 1) + (1 * 1) = 5 in denary as expected.
A logical shift on integers can make a number less precise. For example,
if we divide 00100001 (33 in denary) by 2 the digits would be shifted
one place to the right.
The result is 00010000, which is 16, but the correct result should be
16.5.
ARITHMETIC SHIFTS
Arithmetic shifts are used with signed numbers expressed in two’s
complement format.
LEFT ARITHMETIC SHIFT
A left arithmetic shift is identical to a left logical shift except that the
left-most bit (MSB) is not included because it must remain in place to
indicate the sign.
RIGHT ARITHMETIC SHIFT
When dividing signed binary numbers in two's complement format by
powers of 2, the bits are shifted to the right. They are replaced at the
left by copies of the MSB.
So far, only 8-bit binary numbers have been considered. However, it is
common for data and commands to be represented by 32 and 64 bits.
It is difficult for humans to remember and manipulate 8-bit binary
numbers, but almost impossible to use 32-bit ones. Humans get
confused with large binary numbers, so we use hexadecimal numbers
to represent them. Computers never use hexadecimal numbers.
The hexadecimal system uses 16 digits from 0 to 15. Our denary system
has only digits for O to 9, so the higher hexadecimal digits are
represented by upper case letters.
The following diagram shows how to convert binary to hexadecimal.
It is far easier to say and
remember ‘E6’ than
'11100110'.
This is the reverse of the method used above.
UNIT QUESTIONS