CS 212 Embedded Systems: Data Representation
CS 212 Embedded Systems: Data Representation
Embedded Systems
Lecture 02
Data Representation
Outline
Positional Number Systems
Binary and Hexadecimal Numbers
Base Conversions
Integer Storage Sizes
Binary and Hexadecimal Addition
Signed Integers and 2's Complement Notation
Sign Extension
Binary and Hexadecimal subtraction
Carry and Overflow
Character Storage
Bit Numbering 27 26 25 24 23 22 21 20
Some common
powers of 2
37 = (100101)2
Example:
Solution:
E B 1 6 A 7 9 4
1110 1011 0001 0110 1010 0111 1001 0100
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
Example:
carry: 1 1 1
1C37286A
+ A + B = 10 + 11 = 21
9395E84B Since 21 ≥ 16
Sum = 21 – 16 = 5
AFCD10B5 Carry = 1
1 1 1 1 0 1 1 0
0 = positive Negative
0 0 0 0 1 0 1 0 Positive
Add 1
Examples:
01001101 01001101
– +
00111010 11000110 (2's complement)
00010011 00010011 (same result)
Borrow: 1 1 1 Carry: 1 1 1 1 1
B14FC675 B14FC675
- +
839EA247 7C615DB9 (2's complement)
Practice: What is the range of signed values that may be stored in 20 bits?
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
24 Embedded Systems Tarek Makladi
Range, Carry, Borrow, and Overflow
Unsigned Integers: n-bit representation
Numbers < min Numbers > max
Borrow = 1 Carry = 1
Finite Set of Unsigned Integers
Subtraction Addition
n
min = 0 max = 2 –1
Negative Positive
Finite Set of Signed Integers
Overflow Overflow
n-1
min = -2
n-1
0 max = 2 –1
Null-terminated String
Array of characters followed by a NULL character
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
The first 32 characters of ASCII table are used for control
Control character codes = 00 to 1F (hexadecimal)
Not shown in previous slide
Examples of Control Characters
Character 0 is the NULL character used to terminate a string
Character 9 is the Horizontal Tab (HT) character
Character 0A (hex) = 10 (decimal) is the Line Feed (LF)
Character 0D (hex) = 13 (decimal) is the Carriage Return (CR)
The LF and CR characters are used together
They advance the cursor to the beginning of next line
One control character appears at end of ASCII table
Character 7F (hex) is the Delete (DEL) character