CSC159: Computer Organization Prepared by: Pn. Siti Fatimah Nor Binti Ab Wahab 1
MACHINE LEVEL
REPRESENTATION OF DATA
CHAPTER 2
CSC159: Computer Organization Prepared by: Pn. Siti Fatimah Nor Binti Ab Wahab 2
Objectives
Understand how integers and fractional numbers are represented in binary
Explore the relationship between decimal number system and number systems of other bases (binary, octal, hexadecimal)
Understand signed numbers and unsigned numbers
Understand number representations in two’s complement
Perform arithmetic operations in every base
Understand the method of floating point number representation in IEEE format
CSC159: Computer Organization Prepared by: Pn. Siti Fatimah Nor Binti Ab Wahab 3
Introduction
NUMBERING SYSTEM :
BASE
PLACE
5TH PLACE
4TH PLACE
3RD PLACE
2ND PLACE
1ST PLACE
SINGLE UNIT
● 1ST
PLACE 2ND
PLACE 3RD
PLACE
DECIMAL
105 104 103 102 101 100 ● 10-1 10-2 10-3
100,000 10,000 1,000 100 10 1 0.1 0.01 0.001
1/10 1/100 1/1000
BINARY
25 24 23 22 21 20 ● 2-1 2-2 2-3
32 16 8 4 2 1 0.5 0.25 0.125
1/2 1/4 1/8
OCTAL
85 84 83 82 81 80 ● 8-1 8-2 8-3
32,768 4,096 512 64 8 1 0.125 0.015625 1.953125
X 103
1/8 1/64 1/512
HEXA-DECIMAL
165 164 163 162 161 160 ● 16-1 16-2 16-3
1,048,576
65,536 4,096 256 16 1 0.0625 3.906 X
103
2.4414062 X 104
1/16 1/256 1/4096
CSC159: Computer Organization Prepared by: Pn. Siti Fatimah Nor Binti Ab Wahab 4
Arithmetic Operations in Different Number
Bases The following table shows the equivalent values for decimal numbers in binary, octal and
hexadecimal:
DECIMAL BINARY OCTAL HEXADECIMAL
0 0000 0 0 1 0001 1 1 2 0010 2 2 3 0011 3 3 4 0100 4 4 5 0101 5 5 6 0110 6 6 7 0111 7 7 8 1000 10 8 9 1001 11 9
10 1010 12 A 11 1011 13 B 12 1100 14 C 13 1101 15 D 14 1110 16 E 15 1111 17 F
CSC159: Computer Organization Prepared by: Pn. Siti Fatimah Nor Binti Ab Wahab 5
Radix :
when referring to binary, octal, decimal, hexadecimal, a
single lowercase letter appended to the end of each
number to identify its type.
E.g.
hexadecimal 45 will be written as 45h
octal 76 will be written as 76o or 76q
binary 11010011 will be written as 11010011b
Number Bases
CSC159: Computer Organization Prepared by: Pn. Siti Fatimah Nor Binti Ab Wahab 6
Decimal system:
system of positional notation based on powers of 10.
Binary system:
system of positional notation based powers of 2
Octal system:
system of positional notation based on powers of 8
Hexadecimal system:
system of positional notation based on powers of 16
Number Bases
CSC159: Computer Organization Prepared by: Pn. Siti Fatimah Nor Binti Ab Wahab 7
Early computer design was decimal
Mark I and ENIAC
John von Neumann proposed binary data
processing (1945)
Simplified computer design
Used for both instructions and data
Natural relationship between
on/off switches and
calculation using Boolean logic
On Off
True False
Yes No
1 0
Why Binary?
CSC159: Computer Organization Prepared by: Pn. Siti Fatimah Nor Binti Ab Wahab 8
A computer stores both instructions and data as individual electronic charges.
represent these entities with numbers requires a system geared to the concept of on and off or true and false
Binary is a base 2 numbering system
each digit is either a 0 (off) or a 1 (on)
Computers store all instructions and data as sequences of binary digit
e.g. 010000010100001001001000011 = “ABC”
Binary Numbers
CSC159: Computer Organization Prepared by: Pn. Siti Fatimah Nor Binti Ab Wahab 9
Bit : each digit in a binary number
Byte : consists of 8 bits which is the basic unit of storage on nearly all computers
Each location in the computer’s memory holds exactly 1 byte or 8 bits.
A byte can hold a single instruction, a character or a number
A Word : which is 16 bits or 2 bytes long :
1 0 1 1 0 1 0 1 1 0 1 1 0 1 0 1
A 16-bit computer : its instructions can operate on 16-bit quantities
byte byte
word
bit
Binary Numbers
CSC159: Computer Organization Prepared by: Pn. Siti Fatimah Nor Binti Ab Wahab 10
Place 101 100
Value 10 1
Evaluate 4 x 10 3 x1
Sum 40 3
1’s place 10’s place
43 = 4 x 101 + 3 x 100
Numeric Data Representation FOR
DECIMAL
CSC159: Computer Organization Prepared by: Pn. Siti Fatimah Nor Binti Ab Wahab 11
Numeric Data Representation FOR
DECIMAL
Place 102 101 100
Value 100 10 1
Evaluate 5 x 100 2 x 10 7 x1
Sum 500 20 7
1’s place 10’s place
527 = 5 x 102 + 2 x 101 + 7 x 100
100’s place
CSC159: Computer Organization Prepared by: Pn. Siti Fatimah Nor Binti Ab Wahab 12
Numeric Data Representation
6248 = 40410
Place 82 81 80
Value 64 8 1
Evaluate 6 x 64 2 x 8 4 x 1
Sum for
Base 10 384 16 4
64’s place 8’s place 1’s place
CSC159: Computer Organization Prepared by: Pn. Siti Fatimah Nor Binti Ab Wahab 13
Numeric Data Representation 6,70416 = 26,37210
Place 163 162 161 160
Value 4,096 256 16 1
Evaluate 6 x 4,096 7 x 256 0 x 16 4 x 1
Sum for
Base 10 24,576 1,792 0 4
4,096’s place 256’s place 1’s place 16’s place
CSC159: Computer Organization Prepared by: Pn. Siti Fatimah Nor Binti Ab Wahab 14
Numeric Data Representation
Place 27 26 25 24 23 22 21 20
Value 128 64 32 16 8 4 2 1
Evaluate 1 x 128 1 x 64 0 x 32 1 x16 0 x 8 1 x 4 1 x 2 0 x 1
Sum for
Base 10 128 64 0 16 0 4 2 0
1101 01102 = 21410
CSC159: Computer Organization Prepared by: Pn. Siti Fatimah Nor Binti Ab Wahab 15
Base:
The number of different symbols required to
represent any given number
The larger the base, the more numerals are required
Base 10: 0,1, 2,3,4,5,6,7,8,9
Base 2: 0,1
Base 8: 0,1,2, 3,4,5,6,7
Base 16: 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F
Base or Radix
CSC159: Computer Organization Prepared by: Pn. Siti Fatimah Nor Binti Ab Wahab 16
For a given number, the larger the base
the more symbols required
but the fewer digits needed
Example #1:
6516 10110 1458 110 01012
Example #2:
11C16 28410 4348 1 0001 11002
Number of Symbols vs Number of Digits
CSC159: Computer Organization Prepared by: Pn. Siti Fatimah Nor Binti Ab Wahab 17
Decimal Other bases
Other bases Decimal
Binary Octal
Binary Hexadecimal
Octal Binary
Hexadecimal Binary
Numeric Conversion between Number Bases
CSC159: Computer Organization Prepared by: Pn. Siti Fatimah Nor Binti Ab Wahab 18
CONVERSION :
DECIMAL OTHER BASES
CSC159: Computer Organization Prepared by: Pn. Siti Fatimah Nor Binti Ab Wahab 19
Base 10 42
2 ) 42 ( 0 Least significant bit
2 ) 21 ( 1
2 ) 10 ( 0
2 ) 5 ( 1
2 ) 2 ( 0
2 ) 1 ( 1 Most significant bit
0
Base 2 101010
Remainder
Quotient
From Base 10 to Base 2
CSC159: Computer Organization Prepared by: Pn. Siti Fatimah Nor Binti Ab Wahab 20
Convert 3710 to binary.
* MSB (most-significant-bit) : left most bit
LSB (least-significant-bit) : right most bit
37 ÷ 2 = 18 balance 1 (LSB) 18 ÷ 2 = 9 balance 0 9 ÷ 2 = 4 balance 1 4 ÷ 2 = 2 balance 0 2 ÷ 2 = 1 balance 0 1 ÷ 2 = 0 balance 1 (MSB)
Therefore , 3710 = 1001012
From Base 10 to Base 2
CSC159: Computer Organization Prepared by: Pn. Siti Fatimah Nor Binti Ab Wahab 21
What is the value of 37.687510 in binary?
Steps :
1. Convert the integer to binary by using method shown in previous slide.
2. Convert the decimal point to binary by using the following method.
So, (0.6875)10 = (0.1011)2 ; Therefore, 37.687510 = 100101.10112
0.6875
X 2
(MSB) 1 1.3750 X 2
0 0.7500 X 2
1 1.5000 X 2
(LSB) 1 1.0000
The 1 is saved as result, then dropped and the process repeated
From Base 10 (decimal point) to Base 2
CSC159: Computer Organization Prepared by: Pn. Siti Fatimah Nor Binti Ab Wahab 22
Base 10 135
8) 135 ( 7 Least significant bit
8) 16 ( 0
8) 2 ( 2 Most significant bit
0
Base 8 207
Quotient
Remainder
From Base 10 to Base 8
CSC159: Computer Organization Prepared by: Pn. Siti Fatimah Nor Binti Ab Wahab 23
8 21 5
8 2 2
0
0.25
x 8
2 2.00
From Base 10 (decimal point) to Base 8 Convert 21.2510 to octal.
Therefore,
21.2510 = 25.28
CSC159: Computer Organization Prepared by: Pn. Siti Fatimah Nor Binti Ab Wahab 24
Convert 21.2510 to octal. (OTHER METHOD)
21 ÷ 2 = 10 balance 1 (LSB)
10 ÷ 2 = 5 balance 0
5 ÷ 2 = 2 balance 1
2 ÷ 2 = 1 balance 0
1 ÷ 2 = 0 balance 1 (MSB)
So, 2110 = 101012
Now, 0.25
X 2
(MSB) 0 0.50
X 2
(LSB) 1 1.00
So, 0.2510 = 0.012
From Base 10 (decimal point) to Base 8
Therefore,
Refer to conversion of binary to hexadecimal
21.2510 = 010 101 . 0102
= 25.28
CSC159: Computer Organization Prepared by: Pn. Siti Fatimah Nor Binti Ab Wahab 25
Base 10 5,735
16 ) 5,735 ( 7 Least significant bit
16 ) 358 ( 6
16 ) 22 ( 6
16 ) 1 ( 1 Most significant bit
0
Base 16 1667
Quotient
Remainder
From Base 10 to Base 16
CSC159: Computer Organization Prepared by: Pn. Siti Fatimah Nor Binti Ab Wahab 26
Base 10 8,039
16 ) 8,039 ( 7 Least significant bit
16 ) 502 ( 6
16 ) 31 ( 15
16 ) 1 ( 1 Most significant bit
0
Base 16 1F67
Quotient
Remainder
From Base 10 to Base 16
CSC159: Computer Organization Prepared by: Pn. Siti Fatimah Nor Binti Ab Wahab 27
Convert 2110 to hexadecimal.
21 ÷ 16 = 1 balance 5 (LSB)
1 ÷ 16 = 0 balance 1 (MSB)
Therefore , 2110 = 1516
From Base 10 to Base 16
CSC159: Computer Organization Prepared by: Pn. Siti Fatimah Nor Binti Ab Wahab 28
16 21 5
16 1 1
0
0.25
x 16
4 4.00
From Base 10 (decimal point) to Base 16 Convert 21.2510 to hexadecimal.
Therefore,
21.2510 = 15.416
CSC159: Computer Organization Prepared by: Pn. Siti Fatimah Nor Binti Ab Wahab 29
Convert 21.2510 to hexadecimal. (OTHER METHOD)
21 ÷ 2 = 10 balance 1 (LSB)
10 ÷ 2 = 5 balance 0
5 ÷ 2 = 2 balance 1
2 ÷ 2 = 1 balance 0
1 ÷ 2 = 0 balance 1 (MSB)
So, 2110 = 101012
Now, 0.25
X 2
(MSB) 0 0.50
X 2
(LSB) 1 1.00
So, 0.2510 = 0.012
From Base 10 (decimal point) to Base 16
Therefore,
Refer to conversion of binary to hexadecimal
21.2510 = 10101 . 01002
= 15.416
CSC159: Computer Organization Prepared by: Pn. Siti Fatimah Nor Binti Ab Wahab 30
CONVERSION :
OTHER BASES DECIMAL
CSC159: Computer Organization Prepared by: Pn. Siti Fatimah Nor Binti Ab Wahab 31
Convert 1001102 to decimal.
1001102
= (1 X 25) + (0 X 24) +(0 X 23) +(1 X 22) + (1 X 21) + (0 X 20)
= 32 + 0 + 0 + 4 + 2 + 0
= 3810
Therefore, 1001102 = 3810
1 0 0 1 1 0
25 24 23 22 21 20
32 16 8 4 2 1
1*32 1*4 1*2
32 + 4 + 2 = 3810
From Base 2 to Base 10
CSC159: Computer Organization Prepared by: Pn. Siti Fatimah Nor Binti Ab Wahab 32
Convert E516 to decimal.
E516
= (E X 161) + (5 X 160)
= (14 X 16) + (5 X 1)
= 224 + 5
= 22910
Therefore, E516 = 22910
E 5
161 160
16 1
14*16 5*1
224 + 5 = 22910
From Base 16 to Base 10
CSC159: Computer Organization Prepared by: Pn. Siti Fatimah Nor Binti Ab Wahab 33
Convert E5.A816 to decimal.
From Base 16 (decimal point) to Base 10
E 5 . A 8
161 160 . 16-1 16-2
16 1 . 0.0625 0.00390625
14*16 5*1 . 10*0.0625 8*0.00390625
224 + 5 + 0.625 + 0.03125 = 229.6562510
CSC159: Computer Organization Prepared by: Pn. Siti Fatimah Nor Binti Ab Wahab 34
Convert E5.A816 to decimal. (OTHER METHOD)
1. Firstly convert the number into binary,
2. From Example 15: E516 = 22910
3. Now,
Hex E 5 . A 8
Binary 1110 0101 . 1010 1000
(0.1010 1000)2
= (1 X 2-1) + (0 X 2-2) + (1 X 2-3) + (0 X 2-4) + (1 X 2-5) + (0 X 2-6) + (0 X 2-7) + (0 X 2-8)
= 1/2 + 1/23 + 1/25
= 1/2 + 1/8 + 1/32
= 0.5 + 0.125 + 0.03125
= (0.65625)10
Therefore, E5.A816 = 229.6562510
From Base 16 (decimal point) to Base 10
CSC159: Computer Organization Prepared by: Pn. Siti Fatimah Nor Binti Ab Wahab 35
From Base 8 to Base 10 Convert 72638 to decimal.
7 2 6 3
83 82 81 80
512 64 8 1
7*512 2*64 6*8 3*1
3584 + 128 + 48 + 3 = 376310
CSC159: Computer Organization Prepared by: Pn. Siti Fatimah Nor Binti Ab Wahab 36
72638 = 3,76310
(OTHER METHOD)
7
x 8
56 + 2 = 58
x 8
464 + 6 = 470
x 8
3760 + 3 = 3,763
From Base 8 to Base 10
CSC159: Computer Organization Prepared by: Pn. Siti Fatimah Nor Binti Ab Wahab 37
From Base 8 (decimal point) to Base 10 Convert 46.328 to decimal.
4 6 . 3 2
81 80 . 8-1 8-2
8 1 . 0.125 0.015625
4*8 6*1 . 3*0.125 2*0.015625
32 + 6 + 0.375 + 0.03125 = 38.4062510
CSC159: Computer Organization Prepared by: Pn. Siti Fatimah Nor Binti Ab Wahab 38
CONVERSION :
BINARY HEXADECIMAL
BINARY OCTAL
CSC159: Computer Organization Prepared by: Pn. Siti Fatimah Nor Binti Ab Wahab 39
The nibble approach
Hex easier to read and write than binary
Why hexadecimal?
Modern computer operating systems and networks present variety
of troubleshooting data in hex format
The relationship between BINARY and HEXADECIMAL
1 digit hexadecimal is EQUIVALENT to 4 bits binary
From Base 16 to Base 2
Base 16 1 F 6 7
Base 2 0001 1111 0110 0111
CSC159: Computer Organization Prepared by: Pn. Siti Fatimah Nor Binti Ab Wahab 40
Method:
Get the binary representation for the hexadecimal number.
Example:
Convert F116 to binary.
F116 = F 1
1111 00012
F116 = 1111 00012
From Base 16 to Base 2
CSC159: Computer Organization Prepared by: Pn. Siti Fatimah Nor Binti Ab Wahab 41
Method:
Get the binary representation for the hexadecimal number.
Example:
Convert 2A.5C16 to binary.
2A.5C16 = 2 A . 5 C
0010 1010 . 0101 1100
2A.5C16 = 10 1010 . 0101 112
From Base 16 to Base 2 (decimal point)
CSC159: Computer Organization Prepared by: Pn. Siti Fatimah Nor Binti Ab Wahab 42
Method:
Find the hexadecimal representation for the GROUP of 4 binary numbers.
Example:
Convert 11001112 to hexadecimal number.
110 01112 = 0110 0111
6 7
11001112 = 6716
From Base 2 to Base 16
CSC159: Computer Organization Prepared by: Pn. Siti Fatimah Nor Binti Ab Wahab 43
Method:
Find the hexadecimal representation for the GROUP of 4 binary numbers.
Use the decimal point as your STARTING point.
Example:
Convert 111110.001012 to hexadecimal number.
11 1110.0010 12 = 0011 1110 . 0010 1000
3 E . 2 8
111110.001012 = 3E.2816
From Base 2 to Base 16 (decimal point)
CSC159: Computer Organization Prepared by: Pn. Siti Fatimah Nor Binti Ab Wahab 44
The relationship between BINARY and OCTAL
1 digit octal is EQUIVALENT to 3 bits binary
Base 8 1 2 5 7
Base 2 001 010 101 111
From Base 8 to Base 2
CSC159: Computer Organization Prepared by: Pn. Siti Fatimah Nor Binti Ab Wahab 45
Method:
Get the binary representation for every digit in the octal number.
Example 17:
Convert 538 to binary.
538 = 5 3
101 0112
538 = 1010112
From Base 8 to Base 2
CSC159: Computer Organization Prepared by: Pn. Siti Fatimah Nor Binti Ab Wahab 46
Method:
Get the binary representation for every digit in the octal number.
Example 17:
Convert 27.648 to binary.
From Base 8 to Base 2 (decimal point)
27.648 = 2 7 . 6 4
010 111 . 110 100
27.648 = 10 111 . 110 12
CSC159: Computer Organization Prepared by: Pn. Siti Fatimah Nor Binti Ab Wahab 47
Method:
Find the octal representation for the GROUP of 3 binary numbers.
Example:
Convert 11001112 to octal number.
1 100 1112 = 001 100 111
1 4 7
11001112 = 1478
From Base 2 to Base 8
CSC159: Computer Organization Prepared by: Pn. Siti Fatimah Nor Binti Ab Wahab 48
Method:
Find the octal representation for the GROUP of 3 binary numbers. Use the
decimal point as your STARTING point.
Example:
Convert 11110.001012 to octal number.
11 110.001 012 = 011 110 . 001 010
3 6 . 1 2
11110.001012 = 36.128
From Base 2 to Base 8 (decimal point)
CSC159: Computer Organization Prepared by: Pn. Siti Fatimah Nor Binti Ab Wahab 49
ADDITION AND SUBTRACTION OF
DIFFERENT BASES
CSC159: Computer Organization Prepared by: Pn. Siti Fatimah Nor Binti Ab Wahab 50
Base Problem Largest Single Digit
Decimal 6
+3 9
Octal 6
+1 7
Hexadecimal 6
+9 F
Binary 1
+0 1
Addition
CSC159: Computer Organization Prepared by: Pn. Siti Fatimah Nor Binti Ab Wahab 51
Addition and Subtraction of Binary Numbers
Example ADD
1 1 1 1 1 1
1 0 1 1 1 1 0 0
+ 1 1 0 0 1 1 1 1
1 1 0 0 0 1 0 1 1
Example SUB
0 2 0 1 1 1 2
1 1 1 0 0 0 0 1
- 1 0 1 0 1 1
1 0 1 1 0 1 1 0
CSC159: Computer Organization Prepared by: Pn. Siti Fatimah Nor Binti Ab Wahab 52
Addition of Octal Numbers
Example ADD
1 1 1
3 3 3 3 + 6 = 9 – 8 = 1
+ 4 7 6 1 + 3 + 7 = 11 – 8 = 3
1 0 3 1 1 + 3 + 4 = 8 – 8 = 0
1 + 0 = 1
CSC159: Computer Organization Prepared by: Pn. Siti Fatimah Nor Binti Ab Wahab 53
Subtraction of Octal Numbers
Example SUB
6 81 8
7 2 3 8 + 3 – 6 = 5
- 5 3 6 8 + 1 – 3 = 6
1 6 5 6 – 5 = 1
CSC159: Computer Organization Prepared by: Pn. Siti Fatimah Nor Binti Ab Wahab 54
Addition of Hexadecimal Numbers
Example ADD
1
1 A 2 3 3 + 8 = 11 = B
+ 7 C 2 8 2 + 2 = 4
9 6 4 B 10 + 12 = 22 – 16 = 6
1 + 1 + 7 = 9
CSC159: Computer Organization Prepared by: Pn. Siti Fatimah Nor Binti Ab Wahab 55
Subtraction of Hexadecimal Numbers
Example SUB
E 16 6 16
2 F 7 D 16 + 13 – 14 = 15 = F
- 9 E 16 + 6 – 9 = 13 = D
2 E D F E – 0 = E
2 – 0 = 2
CSC159: Computer Organization Prepared by: Pn. Siti Fatimah Nor Binti Ab Wahab 56
THE ALPHANUMERIC
REPRESENTATION
CSC159: Computer Organization Prepared by: Pn. Siti Fatimah Nor Binti Ab Wahab 57
The Alphanumeric Representation
The data entered as characters, number digits, and
punctuation are known as alphanumeric data.
3 alphanumeric codes are in common use.
ASCII (American Standard Code for Information
Interchange)
Unicode
EBCDIC (Extended Binary Coded Decimal Interchange
Code).
CSC159: Computer Organization Prepared by: Pn. Siti Fatimah Nor Binti Ab Wahab 58
The Alphanumeric Representation
The following
tables show the
comparisons
between the
ASCII code in
binary and
hexadecimal for
the given
characters.
Character Binary Hex A 100 0001 41
B 100 0010 42
C 100 0011 43
D 100 0100 44
E 100 0101 45
F 100 0110 46
G 100 0111 47
H 100 1000 48
I 100 1001 49
J 100 1010 4A
K 100 1011 4B
Space 010 0000 20
Full stop 010 1110 2E
( 010 1000 28
+ 010 1011 2B
$ 010 0100 24
CSC159: Computer Organization Prepared by: Pn. Siti Fatimah Nor Binti Ab Wahab 59
THE DECIMAL REPRESENTATION
CSC159: Computer Organization Prepared by: Pn. Siti Fatimah Nor Binti Ab Wahab 60
The Decimal Representation
BCD (Binary
Coded Decimal) is
often used to
represent decimal
number in binary.
Decimal BCD
0 0000
1 0001
2 0010
3 0011
4 0100
5 0101
6 0110
7 0111
8 1000
9 1001
CSC159: Computer Organization Prepared by: Pn. Siti Fatimah Nor Binti Ab Wahab 61
SIGNED AND UNSIGNED NUMBERS
CSC159: Computer Organization Prepared by: Pn. Siti Fatimah Nor Binti Ab Wahab 62
Signed and Unsigned Numbers
Binary numbers may either signed or unsigned
Oddly, CPU performs arithmetic and comparison operations for both
type equally well, without knowing which type it’s operating on.
An unsigned numbers :
numbers with only positive values
for 8-bit storage location : store unsigned integer value between 0 - 255
for 16-bit storage location : store unsigned integer value between 0 - 65535
Unsigned number can be converted directly to binary numbers and
processed without any special care
CSC159: Computer Organization Prepared by: Pn. Siti Fatimah Nor Binti Ab Wahab 63
For negative numbers, there are several ways used to represent it in
binary form, depending on the process take place :
i. Sign-and-magnitude representation
ii. 1’s complement representation
iii. 2’s complement representation
Signed and Unsigned Numbers
CSC159: Computer Organization Prepared by: Pn. Siti Fatimah Nor Binti Ab Wahab 64
Sign-and-Magnitude
In daily usage, signed integers are represented by a plus or minus sign
and a value.
In the computer, the uses of 0’s and 1’s take place.
0 : plus ( positive)
1 : minus (negative)
The leftmost bit in a binary number is considered the sign bit.
The remaining (n-1) bits are used for magnitude.
CSC159: Computer Organization Prepared by: Pn. Siti Fatimah Nor Binti Ab Wahab 65
Example 1 :
+ 0010 0101
(+37)
0000 0000 0000 0001
(+1)
0111 1111 1111 1111
(+32767)
- 1010 0101
(-37)
1000 0000 0000 0001
(-1)
1111 1111 1111 1111
(-32767)
Sign-and-Magnitude
CSC159: Computer Organization Prepared by: Pn. Siti Fatimah Nor Binti Ab Wahab 66
Example 2 :
What is the sign-and-magnitude representation of the decimal
numbers –31 and +31 if the basic unit is a byte ?
3110 = 111112
Unit is a byte = 8 bits
Sign-and-Magnitude
+31 = 0 0 0 1 1 1 1 1
-31 = 1 0 0 1 1 1 1 1
CSC159: Computer Organization Prepared by: Pn. Siti Fatimah Nor Binti Ab Wahab 67
Example 3 :
What is the sign-and-magnitude representation of the decimal
numbers –31 and +31 if the basic unit is a word?
3110 = 111112
Unit is a word= 16 bits
Sign-and-Magnitude
+31 = 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1
-31 = 1 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1
CSC159: Computer Organization Prepared by: Pn. Siti Fatimah Nor Binti Ab Wahab 68
Example 4 :
What is the decimal equivalent value of the sign-and -magnitude
binary sequence 1011 1001 ?
Sign-and-Magnitude
1 0 1 1 1 0 0 1
Sign is negative 11 10012 = 5710
1011 10012 = - 5710
CSC159: Computer Organization Prepared by: Pn. Siti Fatimah Nor Binti Ab Wahab 69
Addition of 2 numbers in sign-and-magnitude :
using the usual conventions of binary arithmetic
if both have same sign : magnitude are added and the same sign
copied
if the sign different : number that has smaller magnitude is
subtracted from the larger one. The sign is copied from the larger
magnitude.
Sign-and-Magnitude
CSC159: Computer Organization Prepared by: Pn. Siti Fatimah Nor Binti Ab Wahab 70
Example 5 :
What is the decimal value of the sum of the binary numbers 00100110 and 00011110
if they are represented in sign-and-magnitude ? Assume that the basic unit is the byte.
Same signs : magnitude are added
Sign-and-Magnitude
1 1 1 1 1 Sign is positive 100 01002 = 6810
0100 01002= +6810
0 0 1 0 0 1 1 0
+ 0 0 0 1 1 1 1 0
0 1 0 0 0 1 0 0
CSC159: Computer Organization Prepared by: Pn. Siti Fatimah Nor Binti Ab Wahab 71
Example 6 :
What is the decimal value of the sum of the binary numbers 10110011 and 00010110
if they are represented in sign-and-magnitude ? Assume that the basic unit is the byte.
Different signs : Larger magnitude - smaller magnitude
Larger magnitude : 1011 0011
Smaller magnitude : 0001 0110
Sign-and-Magnitude
0 2 0 1 2
Sign is negative 111012 = 2910
1001 11012 = - 2910
1 0 1 1 0 0 1 1
- 0 0 0 1 0 1 1 0
1 0 0 1 1 1 0 1
CSC159: Computer Organization Prepared by: Pn. Siti Fatimah Nor Binti Ab Wahab 72
In base 2, the largest digit is 1.
The 1’s complement is performed simply by changing:
every 0 1 and
every 1 0.
Also known as inversion
1’S Complement Convention
CSC159: Computer Organization Prepared by: Pn. Siti Fatimah Nor Binti Ab Wahab 73
Most popular among computer manufacturers since it does not present any of the
problems of the sign-and-magnitude or 1’s complement.
Positive numbers : using similar procedure as sign-and-magnitude
Given n bits, the range of numbers that can be represented in 2’s complement is
(–(2n )) to (2n-1 –1)
Notice that the range of negative numbers is one larger than the range of the positive
values
2’S Complement Convention
0111 1111
(127)
0000 0000
(0)
1111 1111
(-1)
1000 0000
(-128)
( 2n-1 –1) - (2n)
CSC159: Computer Organization Prepared by: Pn. Siti Fatimah Nor Binti Ab Wahab 74
To represent a negative number in this convention, follow the 3 steps process
below:
Step 1 : Express the absolute value of the number in binary
Step 2 : Change all 0s to 1s and vise versa 1’s complement
Step 3 : Add 1 to the binary number of step 2
Example 1 :
What is the 2’s complement representation of -23 ?
Example 2 :
What is the decimal positive value of the 2’s complement number 11100011 ?
2’S Complement Convention
CSC159: Computer Organization Prepared by: Pn. Siti Fatimah Nor Binti Ab Wahab 75
Example 1 :
What is the 2’s complement representation of -23 ?
2’S Complement Convention
Step:
23 in binary 0 0 0 1 0 1 1 1
1’s (inverse) 1 1 1 0 1 0 0 0
2’s + 1
2’s complement representation
1 1 1 0 1 0 0 1
CSC159: Computer Organization Prepared by: Pn. Siti Fatimah Nor Binti Ab Wahab 76
Example 2 :
What is the decimal positive value of the 2’s complement number 11100011 ?
2’S Complement Convention
Step:
2’s complement representation
1 1 1 0 0 0 1 1
1’s (inverse) 0 0 0 1 1 1 0 0
2’s + 1
Decimal positive value 0 0 0 1 1 1 0 1
CSC159: Computer Organization Prepared by: Pn. Siti Fatimah Nor Binti Ab Wahab 77
The IEEE Floating Point Representation
2 problems with integers;
They can’t express fractions, AND
The range number is limited to the number of bits used.
An efficient way of storing fractions floating point method
involves splitting the fraction into two parts, an exponent and a
mantissa
Computer industry agreed upon a standard for the storage of floating
point numbers
the IEEE 754 standard; uses 32 bits of memory (single precision) or
64 bits (double precision)
CSC159: Computer Organization Prepared by: Pn. Siti Fatimah Nor Binti Ab Wahab 78
IEEE short real : 32 bits (Exponent system = excess 127)
IEEE short real : 64 bits (Exponent system = excess 1023)
Total number
of bits :
1
8
23
Sign Biased exponent Mantissa (fraction)
Total number
of bits :
1
11
52
Sign Biased exponent Mantissa (fraction)
The IEEE Floating Point Representation
CSC159: Computer Organization Prepared by: Pn. Siti Fatimah Nor Binti Ab Wahab 79
Convert 153.7510 to the IEEE floating point format.
Step 1 : convert into binary
Step 2 : put into 1.xxxx X 2y format
Step 3 : get the biased exponent
Step 4 : get the sign (from the question)
Step 5 : identify significand and mantissa
Step 6 : put into the IEEE single precision format
Step 7 : convert into hexadecimal
The IEEE Floating Point Representation
CSC159: Computer Organization Prepared by: Pn. Siti Fatimah Nor Binti Ab Wahab 80
Convert to binary 153.75 = 1001 1001.112
Put into 1.xxxx X 2y = 1.0011 0011 12 x 27
Biased exponent
Exponent = 7
Biased exponent = 127 + y = 127 + 7 = 134
= 1000 01102 (8 bits)
Sign Sign = +ve (0)
Significand
Mantissa
Significand = 1.0011 0011 1
Mantissa = 001 1001 1100 0000 0000 0000 (23bits)
IEEE format
IEEE format :
Sign Biased Exponent Mantissa (23)
0 1000 0110 001 1001 1100 0000 0000 0000
Hexadecimal
0100 0011 0001 1001 1100 0000 0000 0000
4 3 1 9 C 0 0 0
= 4319 C000 h
The IEEE Floating Point Representation
CSC159: Computer Organization Prepared by: Pn. Siti Fatimah Nor Binti Ab Wahab 81
Convert to binary 29 / 128 = 111012 / 27 = 111012 x 2-7
Put into 1.xxxx X 2y = 1.11012 x 24 x 2-7 = 1.11012 x 2-3
Biased exponent
Exponent = -3
Biased exponent = 127 + y = 127 + (-3) = 124
= 0111 11002 (8 bits)
Sign Sign = -ve = 1
Significand
Mantissa
Significand = 1.1101
Mantissa = 110 1000 0000 0000 0000 0000 (23bits)
IEEE format
IEEE format :
Sign Biased Exponent Mantissa (23)
1 0111 1100 110 1000 0000 0000 0000 0000
Hexadecimal
1011 1110 0110 1000 0000 0000 0000 0000
B E 6 8 0 0 0 0
= BE68 0000 h
Eg: Convert -29 / 12810 The IEEE Floating Point Representation
CSC159: Computer Organization Prepared by: Pn. Siti Fatimah Nor Binti Ab Wahab 82
Convert C2F0 000016 in IEEE floating point format to the decimal number.
Step 1 : in hexadecimal
Step 2 : convert into binary
Step 3 : put into the IEEE single precision format
Step 4 : get biased exponent
Step 5 : get the sign
Step 6 : identify significand and mantissa
Step 7 :put into 1.xxxx X 2y
Step 8 : identify actual number
The IEEE Floating Point Representation
CSC159: Computer Organization Prepared by: Pn. Siti Fatimah Nor Binti Ab Wahab 83
In hexadecimal C2F0000016
Convert to binary C 2 F 0 0 0 0 0
1100 0010 1111 0000 0000 0000 0000 0000
Put into IEEE format
IEEE format :
Sign Biased Exponent Mantissa (23)
1 1000 0101 111 0000 0000 0000 0000 0000
Get the biased exponent Biased Exponent:: 1000 0101 = 133
Exponent : 133 – 127 = 6
Sign 1 = -ve
Mantissa
Significand
111 0000 0000 0000 0000 0000
1.111
Put into 1.xxxx X 2y
1.111 x 26
=1111 0002
= 12010
The actual number - 120
The IEEE Floating Point Representation