Lecture5 Data Representn
Lecture5 Data Representn
Lecture5 Data Representn
Outline
Positional Number
Systems
Different Representations of Natural Numbers
XXVII Roman numerals (not positional)
27 Radix-10 or decimal number (positional)
110112 Radix-2 or binary number (also positional)
Fixed-radix positional representation with k
digits
Number N in radix r = (dk1dk2 . . . d1d0)r
Value = dk1r
k1
+ dk2r
k2
+ + d1r + d0
Binary Numbers
Characters
Floating-point numbers
Most
Significant
Bit
Least
Significant
Bit
27
26
25
24
23
22
21
20
Bit Numbering
Converting Binary to
Decimal
27
26
25
24
23
22
21
20
Some
common
powers of 2
10/19/16
37 =
(100101)2
10/19/16
Hexadecimal Integers
16 Hexadecimal Digits: 0 9, A F
More convenient to use than binary numbers
Binary, Decimal, and Hexadecimal
Equivalents
10/19/16
Converting Binary to
Hexadecimal
Each hexadecimal digit corresponds to 4 binary bits
Example:
Convert the 32-bit binary number to hexadecimal
1110 1011 0001 0110 1010 0111 1001 0100
Solution:
1110
1011
0001
0110
1010
0111
1001
0100
10/19/16
Converting Hexadecimal to
Decimal
Examples:
(1234)16 = (1 163) + (2 162) + (3 16) + 4 =
Decimal Value 4660
(3BA4)16 = (3 163) + (11 162) + (10 16) + 4 =
Decimal Value 15268
10/19/16
Converting Decimal to
Hexadecimal
Repeatedly divide the decimal integer by 16
Each remainder is a hex digit in the translated value
most significant
digit
stop when
quotient is
zero
10
Storage Sizes
16
Word
32
Double
Word
64
Storage Type
Unsigned Range
Powers of 2
Byte
0 to 255
0 to (28 1)
Half Word
0 to 65,535
0 to (216 1)
Word
0 to 4,294,967,295
0 to (232 1)
Double Word
0 to 18,446,744,073,709,551,615
0 to (264 1)
10/19/16
11
4 bits
10/19/16
8 bits
KILOBYTE MEGA
GIGABYTE
(Kb)
BYTE (Mb) (Gb)
1,024
bytes
1,024
kilobytes
1024
megabytes
12
TERABYT
E (Tb)
1024
gigabytes
Binary Addition
(54)
(29)
(83)
bit position: 7
10/19/16
13
Hexadecimal Addition
Example:
carry:
1 1
1C37286A
+
9395E84B
AFCD10B5
10/19/16
A + B = 10 + 11 =
21
Since 21 16
Sum = 21 16 = 5
Carry = 1
14
Signed Integers
Sign-Magnitude
Biased
1's complement
2's complement
First part corresponds to the positive numbers ( 0)
Second part correspond to the negative numbers (< 0)
10/19/16
15
Two's Complement
Representation
Positive numbers
Signed value = Unsigned value
Negative numbers
Signed value = Unsigned value
2n n = number of bits
-128 64
32
16
= -128 + 32 + 16 + 4 = -76
8-bit Binary
value
Unsigne
d
value
Signed
value
00000000
00000001
+1
00000010
+2
...
...
...
01111110
126
+126
01111111
127
+127
10000000
128
-128
10000001
129
-127
...
...
...
11111110
254
-2
11111111
255
-1
00100100 = +36
11011011
11011100 = -36
Sign Bit
Sign
bit
1
Negative
Positive
0 = positive
Sign Extension
Step 1: Move the number into the lower-significant bits
Step 2: Fill all the remaining higher bits with the sign bit
This will ensure that both magnitude and sign are correct
Examples
Sign-Extend
to 16 11111111
bits
10110011 =10110011
-77
10110011 = -77
01100010 = +98
10/19/16
19
Add 1
Examples:
2's complement of 6A3D = 95C2 + 1 = 95C3
2's complement of 92F15AC0 = 6D0EA53F + 1 = 6D0EA540
2's complement of FFFFFFFF = 00000000 + 1 = 00000001
10/19/16
20
Binary Subtraction
borro
w:
1 1
carry 1 1
:
1 1
101
0 1 0 0 1 1 0 1 0 1 0 0 1 +
0 0 1 1 1 0 1 0 1 1 0 0 0 1 1 0 (2's complement)
0 0 0 1 0 0 1 1 0 0 0 1 0 0 1 1 (same result)
10/19/16
21