Chapter 1 - Data Representation Notes
Chapter 1 - Data Representation Notes
Chapter 1 - Data Representation Notes
Computers are made up hardware that stores and processes data. If you break a
computer down into its most basic components you have millions of circuits that
either allow electricity to flow, or not. The computer uses electronic circuits to store
one of two values using a switch – the switch is
either ON (1) or OFF (0).
Denary: A system of numbers using ten digits, 0 and 1-9 (also called base-10
system)
Binary: A system of numbers using only 2 bits, 0 and 1 (also called base-2 system)
27 26 25 24 23 22 21 20
Binary to Denary
To convert the binary 111001 into a denary number, use the place values.
Add the place values that are turned ON (1) to get the denary result.
The number is 32+16+8+1 = 57
Denary to Binary
Let’s convert 57 into binary: (Use the same place values.)
• Turn OFF all the place values that are greater than the given number.
(In this case turn OFF 128 and 64)
128 64 32 16 8 4 2 1
0 0
128 64 32 16 8 4 2 1
0 0 1
• Write a 1 under the column heading 32. That leaves us with 57-32 = 25.
Write a 1 under the column heading 16 (because we can take 16 out of
25. 25-16 leaves 9) You should be able to see now that 9 is an 8 and a 1 so we
end up with:
Always double check by adding the columns up at the end. They should give
you the given number
128 64 32 16 8 4 2 1
0 0 1 1 1 0 0 1
The pure binary Conversion that we have studied before can only represent positive
integers as the min number that they can represent is 0. And hence it can be used
for unsigned integers. So, how can computer represent negative numbers?
One’s complement and two’s complement are two important binary concepts. Two’s
complement is especially important because it allows us to represent signed
numbers in binary, and one’s complement is the interim step to finding the two’s
complement.
Two’s complement also provides an easier way to subtract numbers using addition
instead of using the longer, more involving subtraction method
One’s Complement
Two’s Complement
The two’s complement is a method for representing positive and negative integer values in binary.
The useful part of two’s complement is that it automatically includes the sign bit.
Method 1
The MSB (the left most bit) still represents a number but is assumed to be
negative. This means that place values, become:
-128 64 32 16 8 4 2 1
-128 64 32 16 8 4 2 1
0 1 1 1 0 1 0 1
28
-128 64 32 16 8 4 2 1
1 0 0 0 1 0 1 1
Two’s Complement Method 2 tips:
When the number is negative always turn ON MSB which has negative place value,
and use this equation
Example: -73
-128 64 32 16 8 4 2 1
1
-128 + X = -73
X = 128-73
X = 55
-128 64 32 16 8 4 2 1
1 0 1 1 0 1 1 1
55
001011 → Positive
100110 → Negative
Twos Complement Binary to Denary
-128 64 32 16 8 4 2 1
0 1 1 0 0 1 1 0
NOTE: Whenever
64+32+4+2 = 102 MSB is ON the answer
comes as negative
denary value
-128 64 32 16 8 4 2 1
1 0 1 1 0 1 0 1
-128+32+16+4+1 = -75
Note that the range of possible integers represented by one byte is now -128 to
+127.
Two’s complement has the major advantage that addition and subtraction of two
numbers in two’s complement form produces the correct result – as long as the
result is within the permitted range of possible number of bits.
Binary Addition & Subtraction
The binary number system uses only two digits 0 and 1 due to which their addition
is simple. There are four basic operations for binary addition, as mentioned above.
Carry Sum
0+0 0
0+1 1
1+1 1 0
1+1+1 1 1
Overflow:
If the result of an arithmetic operation is to too large (positive or negative) to fit into
the resultant bit-group, then arithmetic overflow occurs
Solution shows the sum is 100102. This result overflows the range
of a 4-bit binary number. If it must be stored as four bits, the most
significant bit is discarded, leaving the incorrect result of 00102. If
the computation had been done using numbers with five or more
bits, the result 100102 would have been correct.
Overflow bit
Remember: −2n−1 ≤ Two's Complement ≤ 2n−1 − 1
−8 ≤ 4 bit ≤ +7
If 2 Two's Complement numbers are added, and they both have the same sign
(both positive or both negative), then overflow occurs if and only if the result has the
opposite sign. Overflow never occurs when adding operands with different signs.
Overflow occurs if
• (+A) + (+B) = −C
• (−A) + (−B) = +C
(−7) 1001
+(−6) 1010
------------
(−13) 1 0011 = 3 Overflow (largest −ve number is −8)
Binary Subtraction
Borrow Method:
Remember 10 in
binary is 2
Twos Complement Method:
NOT means taking
Case1: When binary value is given (like in above figure)
complement
B1 – B2 = B1 + (NOT(B2) +1) /Inverse of each
bit
1100–1010
1 1 0 0 + (NOT(1 0 1 0) + 1)
1 1 0 0 + (0 1 0 1 + 1)
1 1 0 0 + (0 1 1 0)
1 1 0 0
+ 0 1 1 0
1 0 0 1 0
D1 – D2 = B1 + (- D2)
Convert -D2 to binary using 2’s complement
55 – 20 = 55 + (-22)
Binary Coded Decimal
Denary to BCD:
BCD to Denary:
Divide the binary pattern in group of 4 bits starting from right hand side
6 9 4
Some numbers are not proper numbers because they don’t behave like numbers.
For example, a barcode looks like a number but if the barcode for a chocolate bar
is added to the barcode for a sponge cake the result is meaningless. Values that
are written as a string of digits but do not behave like numbers are often stored in
binary coded decimal (BCD)
BCD code is useful for outputting to displays that are always numeric (0 to 9), such
as those found in digital clocks or digital voltmeters.
Hexadecimal System
Hexadecimal system is base 16 system that was developed for humans, as they
are not very good at remembering long strings of numbers or to say binary values
so, to make it easier for us, we can represent every group of 4 bits with a single
hexadecimal digit.
Binary to Hexadecimal
To convert from Binary to Hex you first need to divide the binary value from right
hand side into group of 4 bits.
Hexadecimal to Binary
Hexadecimal to Denary
Convert Hexadecimal to Binary and Binary to Denary
Denary to Hexadecimal
Convert denary to binary and binary to hexadecimal
Byte: a group of eight bits treated as a single unit
Nibble: a group of four bits.