02 DataRepresentation
02 DataRepresentation
• Bit Numbering 7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
1 0 0 1 1 1 0 1
27 26 25 24 23 22 21 20
Some common
powers of 2
Convert Unsigned Decimal to Binary
• Repeatedly divide the decimal integer by 2
• Each remainder is a binary digit in the translated value
37 = (100101)2
E B 1 6 A 7 9 4
1110 1011 0001 0110 1010 0111 1001 0100
Converting Hexadecimal to Decimal
• Multiply each digit by its corresponding power of 16
Value = (dn-1 × 16n-1) + (dn-2 × 16n-2) + ... + (d1 × 16) + d0
• Examples:
stop when
quotient is zero
Double Word 64
carry 1 1 1 1
0 0 1 1 0 1 1 0 (54)
+ 0 0 0 1 1 1 0 1 (29)
0 1 0 1 0 0 1 1 (83)
bit position: 7 6 5 4 3 2 1 0
Hexadecimal Addition
• Start with the least significant hexadecimal digits
• Let Sum = summation of two hex digits
• If Sum is greater than or equal to 16
• Sum = Sum – 16 and Carry = 1
• Example:
carry: 1 1 1
1C37286A A + B = 10 + 11 = 21
+
9395E84B Since 21 ≥ 16
Sum = 21 – 16 = 5
AFCD10B5 Carry = 1
Signed Integers
0 0 0 0 1 0 1 0 Positive
01100010
• Infinite 0s can be =added
+98 to the left of00000000 01100010 = +98
a positive number
• Infinite 1s can be added to the left of a negative number
Two's Complement of a Hexadecimal
• To form the two's complement of a hexadecimal
• Subtract each hexadecimal digit from 15
• 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
–0 1 0 0 1 1 0 1 0 1 0 0 1 1 0 1+
00111010 1 1 0 0 0 1 1 0 (2's complement)
00010011 0 0 0 1 0 0 1 1 (same result)
• Final carry is ignored, because
• Negative number is sign-extended with 1's
• You can imagine infinite 1's to the left of a negative number
• Adding the carry to the extended 1's produces extended zeros
Hexadecimal Subtraction
16 + 5 = 21
Borrow: 1 1 1 Carry: 1 1 1 1 1
B14FC675 B14FC675
- + (2's complement)
839EA247 7C615DB9
Practice: What is the range of signed values that may be stored in 20 bits?
Carry and Overflow
0 0 0 0 1 1 1 1 15 0 0 0 0 1 1 1 1 15
+ +
0 0 0 0 1 0 0 0 8 1 1 1 1 1 0 0 0 248 (-8)
0 0 0 1 0 1 1 1 23 0 0 0 0 0 1 1 1 7
1 1 1 1
0 1 0 0 1 1 1 1 79 1 1 0 1 1 0 1 0 218 (-38)
+ +
0 1 0 0 0 0 0 0 64 1 0 0 1 1 1 0 1 157 (-99)
1 0 0 0 1 1 1 1 143 0 1 1 1 0 1 1 1 119
(-113)
Carry = 0 Overflow = 1 Carry = 1 Overflow = 1
Data Representation ICS 233 – Computer Architecture and Assembly Language – KFUPM © Muhamed Mudawar slide 25
Range, Carry, Borrow, and Overflow
• Unsigned
Numbers Integers: n-bit representation
< min Numbers > max
Borrow = 1 Carry = 1
Finite Set of Unsigned Integers
Subtraction Addition
Negative Positive
Finite Set of Signed Integers
Overflow Overflow
❖ Examples:
✧ ASCII code for space character = 20 (hex) = 32 (decimal)
✧ ASCII code for 'L' = 4C (hex) = 76 (decimal)
✧ ASCII code for 'a' = 61 (hex) = 97 (decimal)
Control Characters