Calculate the two's complement of a given 16 bit number

  • Comp Sci
  • Thread starter blue44
  • Start date
  • Tags
    Bit
In summary, the student is working on an assignment for a computer science course that involves using a program to perform various operations. However, the professor did not provide clear instructions and the student is having trouble finding information online. The student is seeking help with writing an assembly program for calculating two's complement, modifying it to work with a 32-bit number, and computing the average of sixteen 8-bit numbers stored in memory.
  • #1
blue44
1
0
Member warned that some effort must be shown
Homework Statement
Machine Language
Relevant Equations
Simpsim
I'm working on an assignment for a computer science course. The professor did not give very good instruction, and I can't find very much information about the subject online. We are supposed to use this http://www.anne-gert.nl/projects/simpsim/ program to perform various operations including adding, subtracting, multiplying, and dividing values. If I just had something to read or an example of how to use the program, it would be very helpful.
My Attempts:
1- Write an assembly program that calculates two’s complement of a given 16 bit number in 0000 0001
2- Modify your program so that it works for a 32bit number given in 0000 0001 0002 0003
3- Write an assembler program that computes the average of sixteen 8 bit numbers stored in memory and writes the result into 0000.

Thanks.
 
Physics news on Phys.org
  • #2
First, tell us what your understanding is of 2's complement and show an example of adding two 2's complement numbers so we can be sure you've gotten at least that far on your own
 
  • #3
blue44 said:
1- Write an assembly program that calculates two’s complement of a given 16 bit number in 0000 0001
What does 0000 0001 mean? Is it a binary number? If so, that's only 8 bits. Is it in hexadecimal? If so, that's 32 bits.
blue44 said:
2- Modify your program so that it works for a 32bit number given in 0000 0001 0002 0003
The number you show can't be binary, but if it's hexadecimal, it's 64 bits, not 32.
blue44 said:
3- Write an assembler program that computes the average of sixteen 8 bit numbers stored in memory and writes the result into 0000.
An 8-bit number would be ##b_7b_6b_5b_4 b_3b_2b_1b_0##, where each ##b_i## would be either 0 or 1. If 0000 represents a number in hex, that would be 16 bits; i.e., four bits for each hex digit.
 

FAQ: Calculate the two's complement of a given 16 bit number

What is the two's complement of a given 16 bit number?

The two's complement of a given 16 bit number is a method for representing negative numbers in binary form. It is calculated by taking the one's complement (flipping all digits) and adding 1 to the result.

Why do we need to calculate the two's complement of a 16 bit number?

In computer systems, numbers are represented in binary form using a fixed number of bits. This means there is a limit to the range of numbers that can be represented. By using the two's complement, we can represent both positive and negative numbers within this limited range.

How do you calculate the two's complement of a given 16 bit number?

To calculate the two's complement of a given 16 bit number, follow these steps:

  1. Flip all the bits in the number (this is the one's complement).
  2. Add 1 to the result.

Can the two's complement of a 16 bit number be negative?

Yes, the two's complement of a 16 bit number can be negative. The most significant bit (leftmost bit) is used to indicate the sign of the number. If it is 1, the number is negative, and if it is 0, the number is positive.

What is the range of numbers that can be represented using a 16 bit two's complement?

A 16 bit two's complement can represent numbers in the range of -32,768 to 32,767. This is because the most significant bit is reserved for indicating the sign, leaving 15 bits for the actual number representation.

Similar threads

Replies
8
Views
2K
Replies
2
Views
13K
Replies
7
Views
2K
Replies
4
Views
6K
Replies
30
Views
5K
Back
Top