Week 2 Digital Numbers & Operations
Week 2 Digital Numbers & Operations
Operations
Binary numbers:
• What is a binary number?
• How to convert a decimal number into a binary number.
Hexadecimal numbers:
• Definition
• How to use hexadecimal number to represent bits
Arithmetic operations:
• Addition/Subtraction of integer
Shift/Rotation
Design issues
Binary numbers
Binary numbers
Obviously words and other non numerical data are not equivalent
to binary variables.
Remark: To express words with binary variables, another approach
is needed (this is out of the scope of this module)
2016 EE1501 – Digital Logic 4
1. Binary Numbers
value 27 26 25 24 23 22 21 20
(128) (64) (32) (16) (8) (4) (2) (1)
Binary number 0 0 1 0 0 1 1 1
So we can state:
(0 27 ) (0 26 ) (1 25 ) (0 24 ) (0 23 ) (1 22 ) (1 21 ) (1 20 )
Or more simply
(1 25 ) (1 22 ) (1 21 ) (1 20 )
001001112 39
Second method:
value 27 26 25 24 23 22 21 20
(128) (64) (32) (16) (8) (4) (2) (1)
Binary number 0 1 1 0 0 1 0 0
Hexadecimal numbers
Hexadecimal = base 16
Hexadecimal numbers
Decimal 10 11 12 13 14 15
Binary 4-bits 1010 1011 1100 1101 1110 1111
Hexadecimal A B C D E F
Hexadecimal numbers
Hexadecimal numbers
Hexadecimal numbers
Examples:
Convert the binary number : 010110111110
- In decimal
- In hexadecimal
Numerical data
Signed magnitude
Signed magnitude
Solution:
45+1: 00101101 -45+1: 10101101
+00000001 +00000001
0 0 1 0 1 1 1 0 = 46 1 0 1 0 1 1 1 0 = - 46
Problem!!!!
2016 EE1501 – Digital Logic 19
4. Numerical Data
Signed magnitude
Problems with the signed magnitude representation
1’s complement
Two’s complement
Two’s complement
Two’s complement
Exercises
Real numbers
Fixed-point representation
Example: n bits for integer part and m bits for fractional part
n 1
Value i
b .2
i m
i
Integer part Fractional part
bn 1 2 n 1 bn 2 2 n 2 b1 21 b0 20 b1 2 1 b m 2 m
bn 1bn 2 b1b0 .b1 b m
Examples:
Find the range and resolution of a 3.1 fixed point representation.
Range: 7.5
Resolution: 0.5
Fixed-point representation
The point does not exist in a digital system, it is only for the
designer/programmer.
Arithmetic Operations
Addition
0 + 0 = 0
0 + 1 = 1
1 + 0 = 1
1 + 1 = 0 carry 1
(the carry is added to the next column on the left)
Addition
Example 2:
• Convert -3 and -8 into 8-bit signed two’s complement
• Add both 2’s complement number
• Convert to decimal to check the answer.
Example 3:
• Convert -1 and 35 into 8-bit signed two’s complement
• Add both number and convert back to decimal
Subtraction
Subtraction rule
0 - 0 = 0
borrow 1 (1) 0 - 1 = 1
1 - 0 = 1
1 - 1 = 0
Subtraction
Example 2:
• Perform 11-14
Logic shift: All the bits are shifted to the left or right.
And a 0 is placed where there is an empty space.
(left means from LSB towards MSB and right from MSB towards LSB)
Note: The MSB is lost on a left shift and the LSB on a right shift. If the number is
signed then a left shift loses the sign of the number
Left shift
1 1 1 0 0 1 0 0 0
1
Right shift
0
1 1 0 0 1 0 0 1 1
Arithmetic shift: does not shift the MSB thus the sign is preserved
but shift the LSB.
Note: Arithmetic left-shift does not shift the sign bit and places a zero in the LSB. On
the other hand arithmetic right-shift fills the spaces left by the shift with the
value of the sign bit. This has the effect of halving the value irrespective of its
sign
Left shift
1 1 0 0 1 0 0 1
0
Right shift
1 1 0 0 1 0 0 1 1
1 1 0 0 1 0 1 1 0 Rotate left
1 0 0 1 0 1 1 0 0 Rotate right
Design issues
From the resolution, you can determine the number of digit for the
decimal part.
From the minimum and maximum values expected, you can find
the number of bit needed for the integer part.
Example:
• Determine the minimum format for a system that must have a range of 10
(0-10) and a resolution of 0.5.