220 likes | 395 Views
Information and Communication Technology. 3.3-3.4. CHAN CHOI FONG S. 4A (14). 3.3 Number Representation in Computer System. Binary number system is the only number system that computer uses in storing numbers. Bit (basic unit) is a single binary digit
E N D
Information and Communication Technology 3.3-3.4 CHAN CHOI FONG S. 4A (14)
3.3 Number Representation in Computer System • Binary number system is the only number system that computer uses in storing numbers. • Bit (basic unit) • is a single binary digit • any one of two different values can be represent,(for example: true /false ,on/off) • more different values need to represent-> use a series of bits (for example: 8-bit binary number have 256 different values)
Byte • is a data unit used in computer • consist of 8 units
Word • is a natural unit of data used by a computer • the number of bits that the computer can handle at one time (cycle) • word length ( = word size ) is measured in bits • the computer : 16, 32 or 64 bits
Representation of unsigned binary integer • contains no sign symbol ( you can’t have a negative integer here) • in the computer : all bits are used to represent the magnitude
Representation of signed binary integer • Sign-and-magnitude • 0 = positive integer and 1 = negative integer • 1000 00002 = 0000 00002 = 0
Two’s complement • all integers have unique representations
Convert to 2’s complement from the one’s complement • start from the positive integer • invert all bits from “ 0 ” to “ 1 ” and “ 1 ” to “ 0 ” • then you will find the negative integer • Add 1 into that integer eg. 0111 (decimal value : 7 ) 1000 + 1 = 1001 (decimal value : -7 ) 0011 (decimal value : 3 ) 1100 + 1 = 1101 (decimal value : -3 )
Convert to two’s complement code directly • start from the positive integer • when you see the first “ 1 “ in the right side • at the back of the first “ 1 ”, invert all bits from “ 0 ” to “ 1 ” and “ 1 ” to “ 0 ” • then you will find the negative integer eg. 0101 (decimal value : 5 ) 1011 (decimal value : -5 )
eg. 0100 (decimal value : 4 ) 1100 (decimal value : -4 ) • 0000 = 0
Exercise • 0111 1101 (decimal value : 125 ) one’s complement of -12510 : 1000 00102 two’s complement of -12510 : 1000 00112
0100 1110 0101 0000 (decimal value : 20048 ) one’s complement of -632610 : 1011 0001 1010 11112 two’s complement of -632610 : 1011 0001 1011 00002
The advantages of using 2‘s complement over sign-and-magnitude • No duplication of representation of zero • Much simpler circuit to handle calculation (no separated circuit is needed to handle the sign bit) • The range of numbers in two’s complement is wider than the sign-and-magnitude
The advantages of using sign-and-magnitude 1. Easy for human to understand
3.4 Addition and subtraction of different number representations • Addition and subtraction of unsigned integers • “carry”: the sum if digits equals or exceeds the base value eg. Calculate 10102 + 11102 1 0 1 0 + 111111 0 1 1 0 0 0
“borrow” : from the left digit is necessary if a larger digit is subtracted from a smaller one eg. Calculate 110102 - 11012 11 11 0 11 0 - 1 1 0 1 1 1 0 1
overflow error : an error may occur when the result is outside the range eg. 1111 0000 10000 1000 + 0001 1100 - 0001 1000 1 0000 1100 1111 0000
Addition and subtraction of two’s complement numbers • Overflow error just only occurs when two numbers of the same sign are added eg. Calculate -1110+ 2010 1111 0101 + 0001 0100 1 0000 0000 (they have different signs, overflow error will not occur)
eg. Calculate -3310 - 6510 1101 1111 + 1011 1111 11001 1110 (the sign bit of the result is the same, so an overflow error does not occur)
eg. calculate -3310 – 10010 1101 1111 + 1001 1100 1 0111 1011 (the sign bit of the result is different , so an overflow error occurs)