Document

Data Representation
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY
FACULTY OF SCIENCE & TECHNOLOGY
UNIVERSITY OF UWA WELLASSA
1
Converting Number Systems
(1)Decimal to Binary
I. 2510
II. 125.437510
III. 0.17510
(2)Binary to Decimal
I. 110110.11002
II. 111110.10012
(3)Decimal to Octal
I. 125.437510
II. 1105.7510
2
Converting Number Systems…
(4)Octal to Decimal
I. 756.128
II. 16.1158
(5)Decimal to Hexadecimal
I. 125.437510
II. 25.4510
(6)Hexadecimal to Decimal
I. 19D.DE16
II. FD.AC16
3
Converting Number Systems…
(7)Binary to Octal
I. 1100111011101111002
II. 1101111101111012
(8)Octal to Binary
I. 76538
II. 6478
(9)Binary to Hexadecimal
I. 110011101.110111102
II. 1011101.110112
4
Fixed Length Arithmetic
(10)Hexadecimal to Binary
I. DF97.AC16
II. FDA.816
(11)Octal to Hexadecimal
I. 76548
II. 6348
(12)Hexadecimal to Octal
I. A9516
II. B1516
5
Fixed –Length Arithmetic
• Addition
I. 10101 with
II. 10010 with
III. 11.010 with
01000
10111
11.101
• Subtraction
I. 01010 from
II. 00101 from
III. 0101.1 from
11010
11011
1110.1
• Multiplication
I. 10110 from
II. 101.101 from
10101
110.01
• Division
I.
11011
by 101
6
Bitwise Operators
• Bitwise NOT
• Bitwise OR
• Bitwise AND
• Bitwise XOR
Find the bitwise operations of these
numbers 10110 11010
7
Bit shifts
Arithmetic shift
•Left Arithmetic shift
00010111
•Right Arithmetic shift
00010111
1 0 1 1 0
Most significant bit
Least significant bit
8
Negative Number Representation
There are 3 methods
(1)Sign-Magnitude Representation
(2)One’s Complement Representation
(3)Two’s Complement Representation
Sign Magnitude Representation
• The left most bit is use to represent the sign.
• Rest represent the magnitude.
Example-8 bit register
magnitude
Sign
9
Negative Number Representation…
Sign
Positive
Negative
0
1
0
0
0
0
1
0
0
1
Positive 9
1
0
0
0
1
0
0
1
Negative 9
•There are two ways to represent zero.
10
Negative Number Representation…
One’s Complement Representation
• The one’s complement of a binary number is the
result obtain by applying the Bitwise NOT operation
to that number.
Example0
0
0
0
1
0
0
1
+9
1
1
1
1
0
1
1
0
-9
• There are two ways to represent zero.
11
Negative Number Representation…
Two’s Complement Representation
• To find the two’s complement of a binary number,
first take the one’s complement of the number and
then add 2-n to this number.
Here
n= number of decimal places
number of fraction bits
Example10 0 0 0 1 0 0 1 +9
One’s complement
1 1 1 1 0 1 1 0 +1
Two’s complement
12
1 1 1 1 0 1 1 1 -9
Negative Number Representation…
Example20
0
0
0
1
0
1
1
1
1
0
1
.0
.1
1
1
1
1
0
1
.1
1
0
1
+2.25
One’s complement
+.01
Two’s complement
-2.25
• There is only one way to represent zero in two’s
complement method.
13
IEEE Floating Point (FP)
•A Standard for number of bits use to store floating point
number(Real numbers)in modern computers.
•Part of the representation
Eg:
-1.25*10-1
Exponent
Base
Sign
Mantissa
Base 16 : -2*16-1
Base 2 : -1*2-3
14
IEEE Floating Point (FP)…
Examples of formats- for Base 2/Binary numbers
TYPE
Float
Double
Half
Quad
SIGN
1
1
1
1
EXPONENT MANTISSA
8
11
5
15
23
52
10
112
TOTAL
BITS
32
64
16
128
15
IEEE Floating Point (FP)…
Special Values
(1)Signed zero
In IEEE standards zero is signed, meaning that there
exist both “Positive zero ”(+0) and “negative zero”(-0).
(2)NaN
IEEE specifies a special value called “Not a Number”
(NaN) to be returned as the result of certain “invalid ”
operations such as 0/0,sqrt(-1).
16
Other Representation Methods
(1)Binary Coded Decimal(BCD)
Every decimal digit is represented using 4 binary digits
DECIMAL
BCD
0
0000
1
0001
2
0010
3
0011
4
0100
5
0101
6
0110
7
0111
8
1000
9
1001
What is BCD of 1210 & 39510 ?
17
Other Representation Methods(BCD)
BCD numbers are not Binary numbers
Example:Find Summation of 410 and 810
+12
+4
+8
0100
1000
+12
1100
BCD
Not in BCD
representation
0001 0010
18
Other Representation Methods(BCD)…
•Whenever a result in BCD number is greater than or
equal to 1010(decimal 10) then we add 0110 (decimal 6)
to the bit sequence to get the carry over.
•This is due to the fact that with 4 bit representation a
carry over happens only after decimal 16)
19
Other Representation Methods
(2)Excess-3 Code
The Excess 3 code is obtained by,
Binary value in 4 digits+ Decimal 3(0011)=Excess-3 Code
DECIMAL
EXCESS 3
0
0011
1
0100
2
0101
3
0110
4
0111
5
1000
6
1001
7
1010
8
1011
9
1100
What is Excess -3 Code of 39510 ?
20
Other Representation Methods
(3)Alpha Numeric Codes
i. ASCII(American Standard Code for Information
Interchange)
• use 7-bits to represent symbols
i.e. 0-127
128characters
Example
“A”=6510
“a”=9710
ASCII Values
Printable(94)
Non-Printable(34)
21
Other Representation Methods
ii. Unicode
• Can represent any symbol in any language
• Use 16-bits to represent a symbol
i.e.0-65535
65536 characters
Example
“X”=10010
22
Digital Vs Analog
Digital
• Discrete wave form/steps.
• Have a limited number of values, usually two values
are used
Analogue
• Continuous wave form/steps.
• Have values that change steadily over time can have
23
any one of infinite set of values in a range.
Digital Vs Analog…
Digital
• Discrete wave form/steps.
• Have a limited number of values, usually two values
are used
Analogue
• Continuous wave form/steps.
• Have values that change steadily over time can have
any one of infinite set of values in a range.
24
Digital Vs Analog…
•Computers use digital signals to data transmission.
Easier to transmit
Offers less room for errors to occur
•Can represent complicated combinations although use
two states(1,0).
25