Outline
Representing numbers
- Unsigned
- Signed
- Floating point
Representing characters & symbols
- ASCII
- Unicode
Data Representation in Computers
- Data are stored in Registers
- Registers are limited in number & size
- Range of n-bit register for unsigned value is 0 to 2^n-1.
- Range of n-bit register for signed value is -2^n-1+1 to 2^n-1-1.
Data Representation
Number System:
- A Number system of base or radix, r is a system that uses distinct symbols for r digits.
- Decimal number system(Base 10)
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
- Binary number system(Base 2)
- 0, 1
- Octal number system(Base 8)
- 0, 1, 2, 3, 4, 5, 6, 7
- Hexadecimal number system(Base 16)
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F
Decimal
749.4=7*10^2+4*10^1+9*10^0+4*10^-1=700+40+9+0.4=749.4
Conversion between number system
- decimal to binary
- binary to decimal
Quantitative Numbers
Integers(Fixed-point Representation)
- Unsigned
- Signed
Non-integers(Floating-point Representation)
- Floating point numbers - 10.25, 3.33333…, 1/8 = 0.125
1.Signed Integers
- We need a way to represent negative values
- 3 representations
Example – Sign-Magnitude
- If 8-bit register is used what are min & max numbers?
- What are 0000 0000 and 1000 0000 in decimal?
- Representation of zero is not unique
- - 2^(n-1)-1 to + 2^(n-1) -1
- --127 to +127(8-bit)
- -7 to +7(4-bit)
- 0,1…7,-0,-1…-7
Advantages
- Sign reversal
- Finding absolute value |a|
- Flip sign bit
Disadvantage
- Overflow of number
- Example
(a)
1010 +1110
11000 ( where 1 is overflow in binary number system)
(b)
010
+111
1101
(c)
642
+321
1163( overflow in octal)
- Adding a negative of a number is not the same as subtraction
- e.g., add 2 and -3Need different operations
- e.g., add 2 and -3Need different operations
- Zero is not unique
2. Complement Method
- Base = Radix
- Radix r system means r number of symbols
- e.g., binary numbers have symbols 0, 1
- Radix r system means r number of symbols
- e.g., binary numbers have symbols 0, 1
- 2 types
- r’s complement (Radix/Base Component)
- (r – 1)’s complement (Diminished Radix/Base)
- Where r is radix (base) of number system
Examples
1.Decimal
2.Binary
3.9’s & 10’s complement
4. 1’s & 2’s complement
Definition
- Given a number m in base/radix r & having n digits
- (r – 1)’s complement of m is
- (r^n– 1) – m
- r ’s complement of m is
- (r^n– 1) – m + 1= r^n– m
Example:
- (r^n– 1) – m
- (r^n– 1) – m + 1= r^n– m
(a) If m = 5982 & n = 4 digits
- 9’s complement is
9 9 9 9
– 5 9 8 2
4 0 1 7
- 10’s complement
1 0 0 0 0
– 5 9 8 2
4 0 1 8
9 9 9 9
–5 9 8 2
4 0 1 7
+1
4 0 1 8
(b) If m = 382 & n = 3
n = 382
999 1000
-382 - 382
617 618
-382 = 617 or 618
Depending on which complement we use
These are called complementary pair
(i) 1’s complement
Calculated by
(2n – 1) – m
If m = 0101
1’s complement of m on a 4-bit system
1 1 1 1
0 1 0 1 –
1 0 1 0
1
1011(2’s Compliment)
This represents -5 in 1’s complement(1010).
Finding 1’s Complement – Short Cut
Loading..................
Addition with 1’s Complement
If results has a carry add it to LSB (Least Significant Bit)
Example
Add 6 and -3 on a 3-bit system
110
100
1010
+1
011
2’s Complement
Doesn’t require end-around carry operation as in 1’s complement
2’s complement is formed by
Finding 1’s complement
Add 1 to LSB
New range is from -128 to +127
-128 because of +1 to negative value
2’s complement is formed by
Finding 1’s complement
Add 1 to LSB
New range is from -128 to +127
-128 because of +1 to negative value
Example
Pending
Difference B/W 1s and 2s Complement.
1’s complement has 2 zeros (+0, -0)
Value range is less than 2’s complement
2’s complement only has a single zero
Value range is unequal
No need of a separate subtract circuit
Doing a NOT operation is much more cost effective in terms of circuit design
However, multiplication & division is slow.
Detecting Negative Numbers & Overflow
- Check for MSB
- To find magnitude
1’s complement
Flip all bits
2’s complement
Flip all bits + 1
- Rules to detect overflows in 2’s complement
If sum of 2 positive numbers yields a negative result,sum has overflowedIf sum of 2 negative numbers yields a positive result, sum has overflowedElse, no overflow
Floating Point Numbers
- We needed to represent fractional values & values beyond 2n – 1
- +3207.23 =3.20723*10^3
- -0.000321=-3.21*10^-4
where -3=Sign
21=mantissa
10=Radix
-4=Exponent
Formula
N=m.r^e
IEEE Floating Point Standard (FPS)