Docsity

2's Complemet-Basic Unified Engineering-Assignment Solution, Exercises of 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
pf5
pf8
pf9
pfa
pfd
pfe
pff

Partial preview of the text

Download 2's Complemet-Basic Unified Engineering-Assignment Solution and more Exercises Engineering in PDF only on Docsity!

C5 Solutions

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

To Compute 0

0 = 00000000

To Compute โ€“

Step 1. Convert 1 to binary 00000001

Step 2. Flip the bits 11111110

Step3. Add 1 11111111

Therefore โ€“1 = 11111111

To Compute โ€“

Step 1. Convert 12 to binary 00001100

Step 2. Flip the bits 11110011

Step3. Add 1 11110100

Therefore โ€“12 = 11110100

  1. 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

01111

  • 10001 100000

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

C

  1. How many bits do you need to represent a number in excess-16 format? What is the excess-16 representation of 12?

16 = 2^4 = 2 N-1^ โ‡’ N =5.

Five bits are needed to represent the number in excess-16 format.

Step 1. Add 16 to the number 16+12=

Step 2. Convert to binary 12 in excess-16 = 11100

  1. Convert 29/8 into binary 8-bit floating-point representation.

Step1. Set the sign bit to zero since number is positive

Step2. Convert the number into binary representation 29/8 = 3 + 5/ = 011.

Step 3. Normalize the binary representation

0.11101 * 2^2

Step 4.Convert the exponent into excess-

2 = 110

Step 5. Fill in the mantissa

Therefore 29/8 = 01101110

  1. Sketch the basic von Neumann architecture and describe each component in a few lines.

The von Neumann architecture describes a computer with four main sections: the Arithmetic and Logic Unit (ALU) the control unit (CU) the memory the input and output devices (collectively termed I/O) These parts are interconnected by a bundle of wires, a Bus.

C

  1. Write an algorithm to implement the subtraction operation for two positive integers in assembly language. 1. Let the numbers be A, B and the operation be A-B 2. Convert A into binary 3. Convert B into binary 4. Compute 2โ€™s complement of B i. Invert the bits in B using B xor 11111111 ii. Add 1 to B 5. Add A and the 2โ€™s complement of B.
  2. Implement your algorithm in the assembly language describe in the machine language handout. Test your implementation using the SimpleSim simulator.

; Program name : Subtraction using add only ;Programmer : Joe B ;Last Modified : Sep 16 2003

load R1,1 ;1 added for computing 2's complement load R2,FFh ;mask for flipping the bits load R3,first_number ; load R4, second_number ; xor R5, R4,R2 ; flip the 0's and 1's in the second number addi R5,R5,R1 ; add 1 to the flipped bits to get the 2's complement addi R5,R5,R3 ; add the numbers to obtain A - B halt

first_number: db 8 ;A in A-B second_number: db 5 ;B in A-B