Data Representation and Binary Arithmetic
Data Representation and Binary Arithmetic Notes
Conversion Between Number Bases
Binary to Decimal Conversion:
Example: Convert binary value
10101into decimalOptions:
a. 20
b. 22
c. 21
Decimal to Binary Conversion:
Example: Convert decimal
58into binaryOptions:
d.
111010e.
101110f.
111001
Hexadecimal Number System:
Definition: Hexadecimal is referred to as Base 16.
Options:
g. Base 2
h. Base 10
i. Base 16
Hexadecimal to Decimal Conversion:
Example: Convert hexadecimal
2Ainto decimal:Calculation:
$2 \times 16^1 + 10 \times 16^0 = 32 + 10 = 42$
Result:
42
Decimal to Hexadecimal Conversion:
Example: Convert decimal
35into hexadecimal:Calculation:
$35 \div 16 = 2 \text{ remainder } 3$
Result:
23
Learning Outcomes
By the end of this lesson, students will be able to:
Add 2 binary numbers together.
Perform binary shifts on 8-bit binary numbers.
Complete various binary conversions.
Binary Addition
Addition of binary numbers follows specific rules:
Work right to left when adding.
Add the unit's place first and carry over if needed:
Example of simple decimal addition:
$1 + 1 = 10$ in binary, carries 1 to the next column.
Rules of Binary Addition
The following rules apply for binary addition:
$0 + 0 = 0$
$0 + 1 = 1$
$1 + 0 = 1$
$1 + 1 = 0$ (carry 1)
$1 + 1 + 1 = 1$ (carry 1)
Example of binary addition demonstrating various cases:
Calculation:
10111010
Result:Carrying at bit positions leads to a final result of
10101.
Binary Shifts
Binary Shift Left:
Shifting bits to the left (L)
This operation doubles the value of the binary number.
Example:
1000= 8 (in decimal)Shift left once results in
10000= 16 (in decimal)
Binary Shift Right:
Shifting bits to the right reduces the binary value.
This operation halves the value of the binary number.
Example 1:
Start with
1000= 8Right shift once gives you
100= 4Right shift again gives you
10= 2
Example 2:
Start with
1001= 9Right shift once gives you
100= 4Right shift again gives you
10= 2
Logical Shift Operations:
Left shifts multiply a number by 2 for each shift;
Right shifts divide a number by 2.
Example: shifting
1110yields values (in binary):Left shift
1110=11100(multiplies the number).Right shift
1110=111(divides the number).
Loss of Accuracy:
Important to note that shifts may result in loss of accuracy, especially where fractional values are represented.
Example: The value
22 / 4is not exactly5.
Worksheet Task and Exercises
Practical Exercises: Students will perform calculations and compare answers with a partner:
Calculate:
1001 0101 + 0010 0110Add
0100 0011to the result of the previous question.Calculate the left shift of
0110 1011.Explain the effect of a left shift on the binary value.