0% found this document useful (0 votes)
58 views52 pages

Chap 2

Therefore, 5638 = 320 10
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
58 views52 pages

Chap 2

Therefore, 5638 = 320 10
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 52

CSC429: Computer

Organization &
Architecture
Ch t 2
Chapter 2: N
Number
b S System
t

Dr. Norhaslinda Kamaruddin


UiTM Shah Alam
Overview
• Introduction
• Numeric conversion between number
bases
• Performing g arithmetic operation
p in
different number bases
• The alphanumeric representation
• The
Th binary
bi coded
d d decimal
d i l
representation
• Unsigned numbers
• Representation for signed numbers
• IEEE floating point representation
Why not base 10
• Base 10 Number Representation
– That’s why fingers are known as “digits”
– Natural representation for financial transactions
• Floating point number cannot exactly represent $1.20
– Even carries through in scientific notation
• 1.5213 X 104
• Implementing Electronically
– Hard to store
• ENIAC (First electronic computer) used 10 vacuum
tubes / digit
– Hard to transmit
• Need
N d hihighh precision
i i tto encode d 10 signal
i l llevels
l on
single wire
– Messy to implement digital logic functions
• Addition,
Addition multiplication
multiplication, etc
etc.
Binary Representation
• Base 2 Number Representation
– Represent 1521310 as 111011011011012
– Represent 1.2010 as 1.0011001100110011[0011]…2
– Represent 1.5213 X 104 as 1.11011011011012 X 213
• Electronic Implementation
– Easy to store with bi-stable elements
– Reliably transmitted on noisy and inaccurate wires
Bit, Byte and Word
 In a digital system, the numbers are
representedt d in
i bits
bit (smallest
( ll t unit it off data)
d t )
 Bit is short for 'binary digit.' It's a single
digit in a binary number  either 1 or 0.
 Inside a computer, you can think of a bit as
being a mechanical switch, which can be
either
i h switched
i h d on or offff (the
( h earliest
li
computers actually stored information in
memoryy using g mechanical switches,, with
electromagnets to turn each one on or off).
Bit, Byte and Word
 Byte is when 8 bits are grouped together,
 With 8 bits you can store any number

between 0 and 255, since there are 256


different combinations of 1 and 0 to
choose from.
• The original intention was that 8 bits would
be enough to assign a unique number
every possible language character.
• Word is the data that can be handled by a
processor at a time (the register size). The
most common word sizes encountered
today are 8, 16, 32 and 64 bits
Bit, Byte and Word
Number bases
PLACE
BASE
5TH 4TH 3RD 2ND 1ST SINGLE 
SINGLE 1ST 2ND 3RD

PLACE PLACE PLACE PLACE PLACE UNIT PLACE PLACE PLACE
105 104 103 102 101 100 ● 10-1 10-2 10-3
100,00
DECIMAL 10 000
10,000 1 000
1,000 100 10 1 01
0.1 0 01
0.01 0 001
0.001
0
1/10 1/100 1/1000
25 24 23 22 21 20 ● 2-1 2-2 2-3
BINARY 32 16 8 4 2 1 0.5 0.25 0.125
1/2 1/4 1/8
85 84 83 82 81 80 ● 8-1 8-2 8-3
0.01562 1.95312
OCTAL 32,768
, 4,096
, 512 64 8 1 0.125
5 5 X 103
1/8 1/64 1/512
165 164 163 162 161 160 ● 16-1 16-2 16-3
2.44140
HEXA‐ 1,048,
1 048 3.906
3 906 X
65,536 4,096 256 16 1 0.0625 62 X
DECIMAL 576 103
104
1/16 1/256 1/4096
Number bases
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
Numeric Conversion
(Base10 to Base2)

 Conversion of decimal to binary using


table
Convert 8710 and 10510 to binary.
Numeric Conversion
(Base10 to Base2)

 Conversion of decimal to binary


 Divide by 2
Convert 8710 and 10510 to binary.
Numeric Conversion
(Base10 to Base2)

 Conversion of decimal to binary


 Divide by 2
Convert 3710 to binary.

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


Numeric Conversion
(Base10 to Base2)

Convert 37.687510 in binary?


Steps :
1.Convert the integer to binary by using
method shown in Example 1 1.
2.Convert the decimal point to binary by using
the following method.
0 .6 8 7 5
X 2 T h e 1 i s s a ve d as
(M S B) 1 1 .3 7 5 0 r e s u lt , t h en d r o p p e d
X 2 a n d t h e p r o c es s
0 0 .7
7500 r e p e at e d
X 2
1 1 .5 0 0 0
X 2
(LS B ) 1 1 .0 0 0 0
(0.6875)10 = (0.1011)2 ;
37.687510 = 100101.10112
Numeric Conversion
(Base2 to Base10)

 Conversion of binary to decimal using


table
Convert 10101112 and 11010012to
decimal.
decimal
Numeric Conversion
(Base2 to Base10)

 Conversion of binary to decimal


 Multiply by 2
Convert 10101112 and 11010012to decimal.
Numeric Conversion
(Base2 to Base10)

 Conversion of binary to decimal


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


Numeric Conversion
(Base2 to Base10)

 Conversion of binary to decimal


Convert 100110.11012 to decimal.
0.11012
= (1 X 2-1) + (1 X 2-2) + (0 X 2-3) + (1 X 2-4)
= 1/2 + 1/4 + 0 + 1/16
= (13/16)10 or 0.812510

From Example, 1001102 = 3810


Therefore, 100110.11012 = 38.812510
Numeric Conversion
(Base2 and Base10)
Check
1. If the decimal number is even, the equivalent
binary number should end in 0. If the decimal
number is odd,, the binaryy number should end in 1.
2. If the binary number ends in 1, the equivalent
decimal number should be odd. If the binary
number ends in 0,0 the decimal should be even
even.
3. If the decimal number is between 64 and 127, the
equivalent binary number should contain 7 digits
(ignoring any leading 0’s).
4. If the decimal number is between 128 and 255,
the equivalent binary number should contain 8
digits (ignoring any leading 0’s).
Numeric Conversion
(Base10 to Base8)

 Conversion of decimal to octal


 Divide by 8
Convert 432110 to octal.
Numeric Conversion
(Base8 to Base10)

 Conversion of octal to decimal


 Multiply by 8
Convert 103418 to decimal.
Numeric Conversion
(Base8 to Base10)

 Conversion of octal to decimal by table


Convert 5638 to decimal.

5638
= (5 X 82) + (6 X 81) + (3 X 80)
= 320
3 0 + 48 + 3
= 37110

Therefore, 5638 = 37110


Numeric Conversion
(Base8 to Base10)

 Conversion of octal to decimal


Convert 563.28 to decimal.

563.228
563
= (5 X 82) + (6 X 81) + (3 X 80) + (2 X 8-1)
= 371 + ((2 X 1/8))
= 371 + 1/4
= 371.2510

Therefore, 563.28 = 371.2510


Numeric Conversion
(Base10 to Base16)

 Conversion of decimal to hexadecimal


Convert 2110 to hexadecimal.

21 ÷ 16 = 1 balance 5 (LSB)
1 ÷ 16 = 0 balance 1 (MSB)

Therefore , 2110 = 1516


Numeric Conversion
(Base10 to Base16)

 Conversion of decimal to hexadecimal


Convert 21.2510 to hexadecimal.
21 ÷ 2 = 10 balance 1 (LSB)
10 ÷ 2 = 5 bbalance
l 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
21.2510 = 10101 . 01002
= 15.416
Numeric Conversion
(Base16 to Base10)

 Conversion of hexadecimal to decimal


Convert E516 to decimal.

E516
= (E X 161) + (5 X 160)
= (14 X 16) + (5 X 1)
= 224 + 5
= 22910

Therefore, E516 = 22910


Numeric Conversion
(Base16 to Base10)

Convert E5.A816 to decimal.


1. Firstly convert the number into binary,
Hex E 5 . A 816
Binary 1110 0101 . 1010 10002
2. Then convert binary into decimal
(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)
(0 65625)10
Therefore, E5.A816 = 229.6562510
Numeric Conversion
(Base16 to Base2)
(Base8 to Base2)
 Conversion of hexadecimal to binary
Convert F116 to binary.

F116 = 1111 00012


F 1
 Conversion of octal to binary
Convert 648 to binary.
648 = 110 1002
6 4
Numeric Conversion
 Conversion decimal to basen
Divide by n

 Conversion of basen to decimal


Multiply by n
Addition and Subtraction
(Binary Base2)

 Binary numbers operation base2


Example 1

Example 2
Addition and Subtraction
(Octal Base8)

 Octal numbers operation base8


Example 1

Example 2
Addition and Subtraction
(Hexadecimal Base16)

 Hexadecimal numbers operation base16


Example 1

Example 2
Numeric Conversion
~ Exercise
E i ~
1. Perform the addition and subtraction for the following
g
binary numbers:
a) 10 + 111010
b) 10001011 – 100111
c) 1000 + 1011
d) 11000 – 1111

2. Perform the addition and subtraction for the following


octal numbers:
a) 677 + 2356
b) 673 - 25
c) 45 + 47
d) 6006 - 7
Numeric Conversion
~ Exercise
E i ~
3. Perform the addition and subtraction for the following
hexadecimal numbers:

a) B677 + CE79
b) 21BA + ADD
c) 9A3B + FACE
d) A5 - 17
e) 7AC - 3B1
f) FA51 - A76
Signed and Unsigned
N
Numbers
b
 Binary numbers  either signed or unsigned
 CPU performs arithmetic and comparison
operations for both type equally well, without
knowing which type it’s
it s operating on
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
g location : store unsigned
g integer
g
value between 0 - 65535
 Unsigned number can be converted directly
to binary numbers and processed without
any special care
Signed and Unsigned
N
Numbers
b
 For negative numbers, there are several
ways used d to
t representt it in
i bi
binary fform,
depending on the process take place :
i. Sign
Sign-and-magnitude
and magnitude representation
ii. 1’s complement representation
iii. 2’s complement representation
Sign and Magnitude
 In daily usage, signed integers are
represented
t d by
b a plus
l or minus
i sign
i and da
value.
 In the computer, the uses of 0’s
0 s and 1’s
1 s take
place.
 0 : plus ( positive)
 1 : minus (negative)
 The leftmost bit in a binary number is
considered the sign bit
bit.
 The remaining (n-1) bits are used for
g
magnitude.
Sign and Magnitude
 Example 1 :
+ 0100101 0000000000000001 0111111111111111
(+37) (+1) (+32767)
- 1100101 1000000000000001 1111111111111111
(-37) (-1) (-32767)

 Example 2 :
What is the sign-and-magnitude
g g
representation of the decimal numbers –31
and +31 if the basic unit is a byte ?
Sign and Magnitude
 Example 3 :
What is the decimal equivalent value of the
sign-and -magnitude binary sequence
10111001 ?
 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 signg copied
p
 if the sign different : number that has smaller
magnitude is subtracted from the larger one
Sign and Magnitude
 Example 4 :
What is the decimal value of the sum of the
binary numbers 10110011 and 00010110 if
they are represented in sign-and-magnitude?
sign and magnitude?
Assume that the basic unit is the byte.
1’s Complement
C
Conversion
i
 In base 2,, the largest
g digit
g is 1.
 The 1’s complement is performed simply by
changing every 0  1 and every 1  0.
 also known as inversion
 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
2’s Complement
C
Conversion
i
 Given n bits, the range of numbers that can
b represented
be t d iin 2’
2’s complement
l 2n+1 to
t iis –2 t
2n-1 –1

0111 1111 0000 0000 1111 1111 1000 0000


(127) (0) (-1) (-128)
( 2n-1 –1) ( 2n-1 )

 Notice that the range of negative numbers is


one larger than the range of the positive
values
2’s Complement
C
Conversion
i
 To represent a negative number in this
convention,
ti follow
f ll th
the 3 steps
t process b
below
l :
 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
p 3 : Add 1 to the binary
y number of step
p2

Example 1 :
Wh t is
What i the
th 2’s
2’ complement
l t representation
t ti off -23?
23?

Example 2 :
What is the decimal positive value of the 2’s
2s
complement number 111000112 ?
2’s Complement
C
Conversion
i
Perform the following operation in 8-bit 2’s
complement
complement.
2’s Complement
C
Conversion
i
Exercise
2’s Complement
C
Conversion
i
Exercise
IEEE Floating Point
R
Representation
t ti
 2pproblems with integers;
g ; they y can’t express
p
fractions & the range number is limited to the
number of bits used.
 A efficient
An ffi i t way off storing
t i fractions
f ti  floating
fl ti
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)
IEEE Floating Point
R
Representation
t ti
 IEEE short real : 32 bits ((Exponent
p system
y =
excess 127)
Total number
off bits
b : 1 8 23
Sign Biased Mantissa
exponent (fraction)

 IEEE short real : 64 bits (Exponent system =


excess 1023))
Total number
of bits : 1 11 52
Sign Biased Mantissa
exponent (fraction)
IEEE Floating Point
R
Representation
t ti
• Convert 153.7510 to the IEEE floating
gppoint
format.

• Step 1 : convert to binary


• Step 2 : put into 1.xxxx X 2y format
• Step 3 : get the biased exponent
• Step 4 : get the sign
• Step 5 : put into the IEEE single precision
format
IEEE Floating Point
R
Representation
t ti
C
Convert
t tto bi
binary 153 75 = 1001 1001.11
153.75 1001 112
Put into 1.xxxx X 2y = 1.0011 0011 12 x 27
Get the sign (i) Sign = +ve (0)

Exponent = 7
Get the biased
Biased exponent = 127 + y = 127 + 7 = 134
exponent (ii)
= 1000 01102 (8 bits)

Get the mantissa & Significand = 0011 0011 1


the significand (iii) Mantissa = 001 1001 1100 0000 0000 0000 (23bits)
IEEE format :
Putt into
P i t IEEE
Sign Biased Exponent Mantissa
format
0 1000 0110 001 1001 1100 0000 0000 0000

Convert to =0100 0011 0001 1001 1100 0000 0000 0000 ((4 bit–hexa))
hexadecimal = 4319C000h
IEEE Floating Point
R
Representation
t ti
• Convert C2F0000016 in IEEE floating
gppoint
format to the decimal number.

• Step 1 : put into the IEEE single precision


format
• Step 2 : get the sign
• Step 3 : get biased exponent
• Step
p4:p put into 1.xxxx X 2y format
• Step 5 : convert to decimal
IEEE Floating Point
R
Representation
t ti
The actual number = -120

= 1.1112 x 26
Put into 1.xxxx X 2y
= 1111000

G t the
Get th sign
i Si = -ve (1)
Sign
Get the mantissa & Significand = 111
the significand Mantissa = 111 0000 0000 0000 0000 0000 (23 bits)

Get the biased Biased exponent = 133 -127 = 6


exponent Exponent = 1000 0101
IEEE format :
Put into IEEE Sign Biased Exponent Mantissa
format 1 1000 0101 111 0000 0000 0000 0000 0000

Convert to binary 1100 0010 1111 0000 0000 0000 0000 0000
In hexadecimal = C2F00000 h
Thank you

Dr. Norhaslinda Kamaruddin


UiTM Shah Alam

You might also like