Docsity

2's Complement Conversion and Addition Algorithm, Exercises of Aeronautical Engineering

Toggle sidebar
bg1
C5 Solutions
1. Convert the following base 10 numbers into 8-bit 2โ€™s complement notation
0, -1, -12
To Compute 0
0 = 00000000
To Compute โ€“1
Step 1. Convert 1 to binary
00000001
Step 2. Flip the bits
11111110
Step3. Add 1
11111111
Therefore โ€“1 = 11111111
To Compute โ€“12
Step 1. Convert 12 to binary
00001100
Step 2. Flip the bits
11110011
Step3. Add 1
11110100
Therefore โ€“12 = 11110100
docsity.com
pf3
pf4

Partial preview of the text

Download 2's Complement Conversion and Addition Algorithm and more Exercises Aeronautical Engineering in PDF only on Docsity!

C5 Solutions

1. Convert the following base 10 numbers into 8-bit 2โ€™s complement notation

To Compute 0

To Compute โ€“

Step 1. Convert 1 to binary

Step 2. Flip the bits

Step3. Add 1

Therefore โ€“1 = 11111111

To Compute โ€“

Step 1. Convert 12 to binary

Step 2. Flip the bits

Step3. Add 1

Therefore โ€“12 = 11110100

2. Perform each of the following additions assuming that the bit strings represent

values in 2โ€™s complement notation. Identify the cases in which the answer is

incorrect because of overflow.

Answer = 11110

Overflow = 0

โˆด Answer is correct

Answer = 00000

Overflow = 1

โˆด Answer is incorrect

Answer = 11000

Overflow = 0

โˆด Answer is correct

  1. -- convert to modular type
  2. Place_Holder := Byte'Val(Integer'Pos(Number_To_Convert));
  3. -- flip the bits
  4. Place_Holder := Place_Holder xor 2#11111111#;
  5. -- add 1
  6. Place_Holder := Place_Holder + 2#1#;
  7. -- reconvert to integer
  8. Number_To_Convert := Integer'Val(Byte'Pos(Place_Holder));
  9. end if;
  10. -- decimal to binary conversion
  11. -- fill in the bit pattern from left to right
  12. loop
  13. exit when Count = 0;
  14. -- if the remainder is non-zero, the bit is set to 1
  15. -- else the bit is 0
  16. if (Number_To_Convert mod 2) = 1 then
  17. Binary_Number(Count) :='1';
  18. else
  19. Binary_Number(Count) :='0';
  20. end if;
  21. Count := Count -1;
  22. Number_To_Convert := Number_To_Convert/2;
  23. end loop;
  24. Put(Binary_Number);
  25. end Decimal_To_Binary;

67 lines: No errors