Title: Data Representation
1Data Representation
1
2Binary Data Representation
2
- Computers use binary numbers
- Binary numbers correspond directly with values in
Boolean logic. - Computers combine multiple digits to form a
single data value to represent large numbers.
3Binary Data Representation
3
- Numbering System Characteristics
- The number of characters in the number system is
equal to the base of the number system. - Example
- There are 10 characters in the decimal number
system. - (0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
- There are 2 characters in the binary number
system. - (0, 1)
4Binary Data Representation
4
5Binary Data Representation
5
- The fractional part of a numeric value is
separated from the whole number by a period
(radix point) - For Example 5,689.368
- (3 x .1) (6 x .01) (8 x .001)
- 0.3 0.06 0.008 0.368
6Binary Data Representation
6
7Binary Data Representation
7
8Binary Data Representation
8
- Hexadecimal Notation
- The base (radix) of a hexadecimal number system
is 16. - There are 16 characters in the hexadecimal number
system. - There are only 10 characters in the Arabic number
system that can be used to represent some of the
16 characters in the hexadecimal number system. - The letters A, B, C, D, E, F are used to
represent the last 6 characters in the
hexadecimal number system.
9Binary Data Representation
9
10Binary Data Representation
10
- Octal Notation
- Some operating systems and machine language
programs use octal notation. - The base (radix) of an Octal number system is 8.
- There are 8 characters in the octal number
system. (0, 1, 2, 3, 4, 5, 6, 7)
11Binary to Hexadecimal
11
- Notice the Pattern
- Largest 4 digit binary is 1111
- 1 hex digit will represent a 4 digit binary
number - Highest hex digit is F
12Binary to Hexadecimal
12
- Relationship
- Hexadecimal Binary Hexadecimal Binary
- 0 0000 8 1000
- 1 0001 9 1001
- 2 0010 A 1010
- 3 0011 B 1011
- 4 0100 C 1100
- 5 0101 D 1101
- 6 0110 E 1110
- 7 0111 F 1111
13Converting Hex to Binary
13
- Steps
- Convert Hex number to groups of powers of 2.
- Convert to Binary number (Remember to drop
leading zeros for first set of binary numbers -
i.e. first left set)
14Converting Hex to Binary
14
- 11F616
- 1 1 F
6 - 000(1) 000(1) (8)(4)(2)(1) 0(4)(2)0
- 0001 0001 1111 0110
- 10001111101102
Drop Leading zeros
15Convert Binary to Hex
15
- Steps
- Separate into 4 bit groups starting from the
right. - Calculate decimal equivalent (in placeholders in
powers of 2) - Convert to Hexadecimal number
16Convert Binary to Hex
16
- 10001111101102
- 1 0001 1111 0110
- 0001 0001 1111 0110
- 1 1 (8)(4)(2)(1) 0(4)(2)0
- 1 1 15 6
- 11F616
17Converting Octal to Hex
17
- The easiest method to convert between Octal and
Hexadecimal is to convert to binary as an
intermediate step - Regroup binary in groups of 4 for hexadecimal and
3 for octal
18Converting Decimal to Binary
18
- To convert from decimal to Binary or Hexadecimal
we divide the number by the base and record the
remainder. This process is repeated until the
number is 0 and then the final remainder is
recorded. We shall see this in the following
examples.
19Converting Decimal to Binary
19
- Converting 20710 to Binary..
- 207/2 103 remainder is 1
- 103/2 51 remainder is 1
- 51/2 25 remainder is 1
- 25/2 12 remainder is 1
- 12/2 6 remainder is 0
- 6/2 3 remainder is 0
- 3/2 1 remainder is 1
- 1/2 0 remainder is 1
- The binary representation is the remainders read
from the bottom to top. So, 20710 110011112
20Converting Binary to Decimal
20
- We can just sum the values according to their
positions e.g. - 1010011012 28 26 23 22 20
- 256 64 8 4 1
- 33310
- Although this can become difficult as the length
of the binary number increases.
21Converting Decimal to Hex
21
- Converting 20710 to Hexadecimal..
- 207/16 12 remainder is 15 F
- 12/16 0 remainder is 12 C
- Again we read the remainders from the bottom to
the top. So, 20710 CF16. - We usually convert the decimal number to binary
and then covert the binary number to hexadecimal.
22Converting Hex to Decimal
22
- Given 5D2A116 convert it to decimal. We could
just sum the values according to their positions. - 5 5 164 5 65536 327680
- D 13 163 13 4096 53248
- 2 2 162 2 256 512
- A 10 161 10 16 160
- 1 1 160 1 1 1
- Summing the values we get
- 327680 53248 512 160 1 38160110
23Binary Addition
23
- Binary addition is very simple.
- This is best shown in an example of adding two
binary numbers
1
1
1
1
1
1
carries
1 1 1 1 0 1 1 0 1 1
1 --------------------
0
0
1
1
1
0
0
24Binary Subtraction
24
- We can also perform subtraction (with borrows in
place of carries). - Lets subtract (10111)2 from (1001101)2
1 10 0 10 10 0 0 10 1 0 0 1
1 0 1 - 1 0 1 1 1 -------------------
----- 1 1 0 1 1 0
borrows
25Binary Multiplication
25
- Binary multiplication is much the same as decimal
multiplication, except that the multiplication
operations are much simpler
1 0 1 1 1 X 1 0 1
0 ----------------------- 0 0 0 0
0 1 0 1 1 1 0 0 0 0 0 1 0 1
1 1 ----------------------- 1 1 1 0 0 1
1 0
26How To Represent Signed Numbers
26
- Plus and minus sign used for decimal numbers
- 25 (or 25), -16, etc.
- For computers, desirable to represent everything
as bits. - Three types of signed binary number
representations - signed magnitude, 1s complement, 2s complement.
- In each case left-most bit indicates sign
- positive (0) or negative (1).
Consider signed magnitude
27Ones Complement Representation
27
- The ones complement of a binary number involves
inverting all bits. - 1s comp of 00110011 is 11001100
- 1s comp of 10101010 is 01010101
- For an n bit number N the 1s complement is
(2n-1) N. - Called diminished radix complement by Mano since
1s complement for base (radix 2). - To find negative of 1s complement number take
the 1s complement.
28Twos Complement Representation
28
- The twos complement of a binary number involves
inverting all bits and adding 1. - 2s comp of 00110011 is 11001101
- 2s comp of 10101010 is 01010110
- For an n bit number N the 2s complement is
(2n-1) N 1. - Called radix complement by Mano since 2s
complement for base (radix 2). - To find negative of 2s complement number take
the 2s complement.
29Twos Complement Shortcuts
29
- Algorithm 1 Simply complement each bit and
then add 1 to the result. - Finding the 2s complement of (01100101)2 and of
its 2s complement - N 01100101 N 10011011
- 10011010 01100100
- 1
1 - --------------- ---------------
- 10011011 01100101
- Algorithm 2 Starting with the least significant
bit, copy all of the bits up to and including the
first 1 bit and then complementing the remaining
bits. - N 0 1 1 0 0 1 0 1
- N 1 0 0 1 1 0 1 1
30Finite Number Representation
30
- Machines that use 2s complement arithmetic can
represent integers in the range - -2n-1 lt N lt 2n-1-1
- where n is the number of bits available for
representing N. Note that - 2n-1-1 (011..11)2 and 2n-1
(100..00)2 - For 2s complement more negative numbers than
positive. - For 1s complement two representations for zero.
- For an n bit number in base (radix) z there are
zn different unsigned values. - (0, 1, zn-1)
311s Complement Addition
31
- Using 1s complement numbers, adding numbers is
easy. - For example, suppose we wish to add (1100)2 and
(0001)2. - Lets compute (12)10 (1)10.
- (12)10 (1100)2 011002 in 1s comp.
- (1)10 (0001)2 000012 in 1s comp.
Step 1 Add binary numbers Step 2 Add carry to
low-order bit
0 1 1 0 0 0 0 0 0 1 -------------- 0 0 1 1
0 1 0 -------------- 0 1 1 0 1
Add
Add carry
Final Result
321s Complement Subtraction
32
- Using 1s complement numbers, subtracting numbers
is also easy. - For example, suppose we wish to subtract (0001)2
from (1100)2. - Lets compute (12)10 - (1)10.
- (12)10 (1100)2 011002 in 1s comp.
- (-1)10 -(0001)2 111102 in 1s comp.
0 1 1 0 0 - 0 0 0 0 1 -------------- 0 1
1 0 0 1 1 1 1 0 -------------- 1 0 1 0 1 0
1 -------------- 0 1 0 1 1
Step 1 Take 1s complement of 2nd operand Step
2 Add binary numbers Step 3 Add carry to low
order bit
1s comp
Add
Add carry
Final Result
332s Complement Addition
33
- Using 2s complement numbers, adding numbers is
easy. - For example, suppose we wish to add (1100)2 and
(0001)2. - Lets compute (12)10 (1)10.
- (12)10 (1100)2 011002 in 2s comp.
- (1)10 (0001)2 000012 in 2s comp.
0 1 1 0 0 0 0 0 0 1 -------------- 0 0 1 1
0 1
Add
Step 1 Add binary numbers Step 2 Ignore carry
bit
Final Result
Ignore
342s Complement Subtraction
34
- Using 2s complement numbers, follow steps for
subtraction - For example, suppose we wish to subtract (0001)2
from (1100)2. - Lets compute (12)10 - (1)10.
- (12)10 (1100)2 011002 in 2s comp.
- (-1)10 -(0001)2 111112 in 2s comp.
0 1 1 0 0 - 0 0 0 0 1 -------------- 0 1
1 0 0 1 1 1 1 1 -------------- 1 0 1 0 1 1
Step 1 Take 2s complement of 2nd operand Step
2 Add binary numbers Step 3 Ignore carry bit
2s comp
Add
Final Result
Ignore Carry
35Summary
35
- Binary numbers can also be represented in octal
and hexadecimal - Easy to convert between binary, octal, and
hexadecimal - Signed numbers represented in signed magnitude,
1s complement, and 2s complement - 2s complement most important (only 1
representation for zero). - Important to understand treatment of sign bit for
1s and 2s complement.
36Goals of Computer Data Representation
36
- Compactness - compact data representation
requires less storage space and less expensive
processing and storage devices. - Accuracy - the accuracy of representation
increases with the number of data bits used.
37Goals of Computer Data Representation
37
- Range routine calculations can generate
quantities that are either too large or too
small to be stored within finite circuitry. - Ease of manipulation - the efficiency of a
processor depends on its complexity. - Standardization - various organizations have
created standard data encoding methods for
communication among computer systems and their
components.
38CPU Data Types
38
- Five Primitive Data Types
- Integer
- Excess Notation
- Twos Complement Notation
- Real number
- Floating Point Notation
- Character
- Boolean
- Memory address
39CPU Data Types
39
- Integer
- An integer is a whole number
- (For example 3, 5, 6)
- Integers can be signed or unsigned
- A signed integer uses one bit to represent the
sign - The sign bit is the high order bit
- Excess notation is used to represent signed
integers
40CPU Data Types
40
41CPU Data Types
41
- Twos Complement Notation
- Nonnegative integer values are represented as
ordinary binary numbers - Negative integer values are represented using
(Complement of positive value 1) - The complement of a number is formed by
changing all 1 bits to 0 and all 0 bits to 1
42CPU Data Types
42
- Real Numbers
- A real number can contain both whole and
fractional components - The whole portion appears to the left of the
radix point - The fractional portion appears to the right of
the radix point
43CPU Data Types
43
Real Number
44CPU Data Types
44
Scientific Notation
45CPU Data Types
45
- Floating Point Notation
- Floating point notation is used to represent very
small numbers and very large numbers - Values can either be very large or very small,
but not both at the same time
46CPU Data Types
46
Floating Point Notation
47CPU Data Types
47
- Character Data
- An individual symbol is a character.
- Characters grouped together form a string.
- Character data can only be represented in the
computer system using a coding scheme.
48CPU Data Types
48
- Binary Coded Decimal (BCD)
- Character coding method used by early IBM
mainframe computers. - Characters are encoded as strings of six bits.
- 64 - (26) symbols are represented.
49CPU Data Types
49
- Extended Binary Coded Decimal Interchange Code
- 8 bit coding method used by IBM mainframe
computers. - Characters are encoded as strings of eight bits.
- 256 - (28) symbols are represented.
50CPU Data Types
50
- ASCII
- - American Standard Code of Information
Interchange - Coding method used in data communication that has
been adopted by the United States. - 7-bit and 8-bit formats
- Includes device control codes
51CPU Data Types
51
52CPU Data Types
52
- Unicode
- Multilingual character encoding standard
encompassing all of the worlds written
languages. - Characters are coded using 16 bit strings.
- 65,535 (216) characters are represented.
53CPU Data Types
53
- Boolean Data
- Two data values true and false.
- Data is represented using a single bit.
- Binary 1 can represent true and binary 0 can
represent false.
54CPU Data Types
54
- Memory Addresses
- Flat memory model Memory addresses can be
represented using a single integer. - Segmented memory model
- Memory addresses require multiple integers.
55Number Systems
Ones Complement
Shortcut method simply compute bit wise
complement 0111 -gt 1000
56Computer Arithmetic
57Chapter Overview
- Binary Number Representation
- Sign Magnitude, Ones Complement, Twos
Complement - Binary Addition
- Full Adder Revisited
- BCD Circuits
- Combinational Multiplier Circuit
58Number Systems
Representation of Negative Numbers
- Representation of positive numbers same in most
systems - Major differences are in how negative numbers are
represented - Three major schemes
- sign and magnitude
- ones complement
- twos complement
- Assumptions
- we'll assume a 4 bit machine word
- 16 different values can be represented
- roughly half are positive, half are negative
59Number Systems
Ones Complement
- Subtraction implemented by addition 1's
complement - Still two representations of 0! This causes some
problems - Some complexities in addition
60Number Representations
Twos Complement
like 1's comp except shifted one
position clockwise
- Only one representation for 0
- One more negative number than positive number
61Number Systems
Twos Complement Numbers
Shortcut method
Twos complement bitwise complement 1 0111 -gt
1000 1 -gt 1001 (representation of -7) 1001 -gt
0110 1 -gt 0111 (representation of 7)
62Number Systems
Overflow Conditions
Add two positive numbers to get a negative
number or two negative numbers to get a positive
number
-1
-1
0
0
-2
-2
1111
0000
1
1111
0000
1
1110
1110
0001
0001
-3
-3
2
2
1101
1101
0010
0010
-4
-4
1100
3
1100
3
0011
0011
-5
-5
1011
1011
0100
4
0100
4
1010
1010
-6
-6
0101
0101
5
5
1001
1001
0110
0110
-7
-7
6
6
1000
0111
1000
0111
-8
-8
7
7
-7 - 2 7
5 3 -9
63Networks for Binary Addition
Half Adder
With twos complement numbers, addition is
sufficient
Half-adder Schematic
64Networks for Binary Addition
Full Adder
Cascaded Multi-bit Adder
usually interested in adding more than two bits
this motivates the need for the full adder
65Networks for Binary Addition
Adder/Subtractor
A - B A (-B) A B 1
66Arithmetic Logic Unit Design
74181 TTL ALU
67BCD Addition
BCD Number Representation
Decimal digits 0 through 9 represented as 0000
through 1001 in binary
Addition
5 0101 3 0011 1000 8
5 0101 8 1000 1101 13!
Problem when digit sum exceeds 9
Solution add 6 (0110) if sum exceeds 9!
5 0101 8 1000 1101 6
0110 1 0011 1 3 in BCD
9 1001 7 0111 1 0000 16 in
binary 6 0110 1 0110 1 6 in BCD
68BCD Addition
Adder Design
Add 0110 to sum whenever it exceeds 1001 (11XX or
1X1X)
69Combinational Multiplier
Basic Concept
multiplicand multiplier
1101 (13) 1011 (11) 1101
product of 2 4-bit numbers is an 8-bit number
1101
Partial products
0000
1101
10001111
(143)
70Combinational Multiplier
Partial Product Accumulation
A0 B0 A0 B0
A1 B1 A1 B0 A0 B1
A2 B2 A2 B0 A1 B1 A0 B2
A3 B3 A2 B0 A2 B1 A1 B2 A0 B3
A3 B1 A2 B2 A1 B3
A3 B3
A3 B2 A2 B3
S6
S4
S7
S5
S3
S2
S1
S0
71Combinational Multiplier
Partial Product Accumulation
Note use of parallel carry-outs to form higher
order sums 12 Adders, if full adders, this is 6
gates each 72 gates 16 gates form the partial
products total 88 gates!
72Review
We have covered
Binary Number Representation positive
numbers the same difference is in how negative
numbers are represented twos complement
easiest to handle one representation
for zero, slightly complicated
complementation, simple addition Binary
Networks for Additions basic HA, FA BCD
Adders Simple extension of binary adders