Example binary to octal notation.
Given: 1111101.10012
001 111 101 . 100 100
1 7 5 . 4 4
= 175.448
Example octal to binary notation.
Given: 56.38
5 6 . 3
101 110 001
= 101110.0012
Hexadecimal ( base 16 )
The hexadecimal number system uses the following digits:
0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F
Binary digits are grouped into sets of 4 bits, called a nibble.
Each possible combination of four binary digits is given a symbol, as follows:
0000 = 0 0100 = 4 1000 = 8 1100 = C
0001 = 1 0101 = 5 1001 = 9 1101 = D
0010 = 2 0110 = 6 1010 = A 1110 = E
0011 = 3 0111 = 7 1011 = B 1111 = F
Because 16 symbols are used, the notation is called hexadecimal and the 16 symbols are the hexadecimal digits.
|
DECIMAL, BINARY AND HEXADECIMAL TABLE. |
Converting decimal to hexadecimal:
26
÷ 16 = 1 with A left over
1
÷ 16 = 0 with 1 left over
Answer: 2610
= 1A16.
Converting binary to hexadecimal:
To
convert hexadecimal to binary, simply reverse the process by converting each
hexadecimal digit. For example, to convert 7B to binary, begin by breaking the
number apart: List each digit, namely 7 and B and then convert:
7=
0111 B = 1011
Then
list the numbers from left to right, namely 0111 1011.
Example given: 101110.01102
0010 1110 . 0110
2 E 6
Answer : 2E.616
* PLEASE REFER THE FOUR BINARY DIGITS GIVEN ABOVE
Converting hexadecimal to binary:
Example given: 1A.816
1 A . 8
0001 1010 . 1000
Answer: 00011010.10002
Converting octal to hexadecimal:
example given: 23.478
In this case there are two steps to be followed:
- 1st step convert octal to binary
2 3 . 4 7
010 011 . 100 111
= 010011.1001112
- 2nd step binary to hexadecimal
0001 0011 . 1001 1100
1 3 . 9 C
Answer : 13.9C16
Converting hexadecimal to octal:
example given: 26B.5D16
2 6 B . 5 D
0010 0110 1011 . 0101 1101
= 001001101011.010111012
001 001 101 011 . 010 111 010
1 1 5 3 . 2 7 2
Answer : 1153.2728
BINARY REPRESENTATIONS
Binary numbers can be stored in 2 different formats.
- unsigned numbers
- signed numbers ( signed magnitude, one's complement, two's complement )
Sign-magnitude representation
Assign the leftmost ( most significant ) bit to the sign bit.
If the sign bit is 0: positive eg: +18 = 00010010
If the sign bit is 1: negative - 18 = 10010010
The remaining bits are used to represent the magnitude of the binary number in the unsigned binary notation.
Two representations of zero ( +0 and -0 )
- cause complication for computers checking numbers for equality.
Need to consider both sign and magnitude in arithmetic.
For performing addition and subtraction, we required a special consideration of both sign of the numbers to properly compute of the operation.
Two's complement
Decimal -> 2's complement
1. If A is positive, represent it using the sign-magnitude representation. The leftmost bit must be 0, and the remaining bits are the binary for the integer. Be careful there are enough bits available to represent the number.
2. If A negative, first represent in binary +A.
a. Flip all the 1's to 0's and the 0's to 1's.
b. Add 1 to the result using unsigned binary notation.
For example:
What is -5 in two's complement?
5 = 0101
1010 ( 1's complement of 0101 )
+ 1
---------
1011 ( 2's complement of 0101 )
---------
2's complement -> decimal
1. If the leftmost bits is 0, the number is positive. Compute the magnitude as an unsigned binary number.
2. If the leftmost bits is 1, the number is negative.
a. Flip all the 1's to 0's, and the 0's to 1's.
b. Add 1 to the result using unsigned binary notation.
c. Compute the value as if it were an unsigned binary value, say it is B. This is the magnitude of the negative number.
d. The actual value is -B.
For example:
What
is the decimal value of the two’s complement binary value 11100?
Leftmost 1=-ve,
Complement / flip=00011
Add 1=00100
Compute the value=4
Ans=-4
11100
00011 --> flip
00011
+ 1
----------
00100
----------
= 4
Answer : -4
Benefit of two's complement
- One representation of zero
- Arithmetic works easily
- Negating is fairly easiy
eg: 3 = 00000011
Boolean complement gives
11111100
Add 1 to lSB
11111101
Addition and subtraction for the Signed binary numbers in 2's complement
-Normal binary addition
-Monitor sign bit for overflow
-Take twos compliment of subtrahend and
add to minuend
i.e. a - b = a + (-b)
-So we only need addition and complement
circuits
Addition
0 + 0 = 0
1 + 0 = 1
1 + 1 = 0 [ carry of 1 to next column ( next more significant position to the left ) ]
1 + 1 + 1 = 1 [ carry of 1 to next column ( next more significant position to the left ) ]
For example:
6 = 0110 --> flip
1001
+ 1
---------
1010
---------
-610 1010
+710 0111
-------- --------
110 10001 = 0001
-------- --------
Subtraction
1. Form 1's complement of B.
2. Add 1 to 1's complemet of B to form 2's complement.
3. Add 2's complement of B to A.
4. Check carry (CY) out of MSB and sign bit (MSB) of result.
a. If CY = 1 and result is positive. The result is probably valid.
b. If CY = 0 and result is negative. The result is probably valid.
Borrow =1
For example:
5 - 2
how to get 1110?
2= 0010 --> flip
1101
+ 1
--------
1110
--------
Normalized Floating-point
For example:
110.111012
Answer : 1.1011101 x 22
* if you move to the front it will become positive
0.01011012
Answer : 1.01101 x 2-2
* if you move to the back it will become negative
Underflows
• below
the minimum number that can be represented.
• minimum
number: is 2-127
in single precision.
• An
underflow condition is identified by setting all the bits in the exponent to
zero and all bits in the mantissa to zero. Clearly in this case the number
represented is 0. There are 2 types of underflow: +0 and -0, distinguished by
the first bit in the word, i.e. the sign.
Overflow
• x
is larger than the largest possible number that can be represented in a word.
• The
exponent is simply set to its maximum value.
• while
the mantissa is zero.
A NaN
• performs
an illegal operation.
• Examples
: 0/0, 1/1 etc.
•
results which are indeterminate.
•
represented within a computer word as an exponent of 255 and a nonzero
mantissa. The sign can take either value.
Prepared by IMAN SOFEA ZAKARIA
1121115830