Files
2024-01-16 13:48:46 +00:00

3.7 KiB
Raw Permalink Blame History

a) Choose a number between 51 and 70. This will be number A. Choose another number between 80 and 120. This will be number B. Using 2s complement 8-bit binary arithmetic, calculate number A number B giving your answer in binary and decimal. (5 marks)

Number A - 64 - 0100 0000 Number B - 96 - 0110 0000

Binary Subtraction
Num A 0100 0000
Num B 0110 0000
Flip B 1001 1111
Add 1 1010 0000
Num A 0100 0000
Num B 1010 0000
Output 1110 0000
1s Comp 0001 1111
2s Comp -0010 0000
Decimal -32

b) Choose one number from the set { 30, 31, 33, 34, 35, 35, 37, 38, 39 } this is numberC. Choose a number from { 3, 5, 6 } this is numberD. Using 8-bit binary arithmetic, calculate numberC × numberD giving your answer in binary and decimal.

Number C - 34 - 0010 0010 Number D - 6 - 0000 0110 - 2^1, 2^2

Binary Multiplication
Num C 0010 0010
Mult 2^1 0100 0100
Num C 0010 0010
Mult 2^2 1000 1000
Add 1100 1100
Decimal 204

Here, we split our exponent into 2, giving a value of 2 and 4 (2^2), so we can multiply the mantissa by both, and add them together.

c) Using numberC and numberD from (b), use binary arithmetic to calculate: numberC.125 + numberD.375 giving your answer in binary and decimal. Convert numberC.125 into IEEE-754 format.

numberC 0010 0010
Floating Point 0010 0010 . 001
C.125 100010.001
Decimal 34.125
numberD 0000 0010
Floating Point 0000 0110 . 011
D.375 110.011
Decimal 6.375
Binary Addition
Num C.125 0010 0010.001
Num D.375 0000 0110.011
Add 0010 1000.100
Decimal 40.5

Here, we add the floating points to the two numbers, and convert both to decimal to check our answer. Adding them together in the 3rd table to get an answer in both decimal and binary.

Convert -> Floating Point Binary Decimal
Num C.125 100010.001 34.125
Normalised 1.00010001 x 2^5 34.125
Remove leading 1 0.00010001 0.06640625
Sign 0 (Positive) 0
Exponent 10000100 132 (2^5)
Mantissa 00010001000000000000000 1.06640625
Total 01000010000010001000000000000000 2^5 x 1.06640625

Here, since the sign is positive, it takes the value of 0. The exponent is 2^5, but in IEEE-754, you would take the exponent from the normalised value and add to the bias (127 in 32bit). I then got the mantissa by removing the leading 1, since it is assumed, from the normalised value, and adding the trailing 0's to get 23 bits. Concatenating these values I then get the final answer in decimal and binary.

d) Choose a number between 140 and 160 - this is numberE. Convert numberE to hexadecimal. Choose a number between 170 and 255 - this is numberF. Convert numberF into octal. Using 8-bit binary, calculate numberE OR numberF. Give your answer in binary, octal, decimal and hexadecimal.

NumberE - 160 NumberF - 223

NumberE 160
Binary 0b10100000
Hexadecimal 0xA0
NumberF 223
/8 27r7
/8 3r3
/8 0r3
Octal 0337
Binary 1101 1111
NumE OR NumF
NumE 0b1010 0000
NumF 0b1101 1111
OR (Binary) 0b11111111
OR (Decimal) 255
OR (Hexadecimal) 0xFF
OR (Octal) 0377

Here, I have picked two numbers, the first of which is converted to hexadecimal, and the second converted to octal using a division conversion method on the decimal value. Then I have done a bitwise operation for OR on the two binary values to get a binary value, and then converted to decimal, hexadecimal and octal - in this case it is the maximum value for each using 8 bit binary.