I've been trying to convert the number -441 to binary, but I don't really know how I can accomplish this.
I first converted 441 to binary which is: 110111001Then I'm supposed to take the compliment of this number which is: 001000110And then I'd have to add one which would result in: 001000111
The exercise says that I have to give the binary representation in 10 bit and 16 bit, and so I though I could just put a zero before the number and that's it, but after I lot of searching I discovered that I'm supposed to put a ONE before the number, why is this the case?
How would I go about converting -441 to a 16 bit number?
Thank you.
bertieb
5,8111111 gold badges2929 silver badges4444 bronze badges
MaximMaxim
2 Answers
You're confused because you forgot that there must be something that distinguishes positive numbers from negative ones.
Let's say you want to store non-negative numbers on 8 bits.
So you can store numbers in range 0-255 on 8 bits. 255 = 28 Windows 10 action center settings. - 1. (2 is the base of binary system, 8 is the number of bits, 1 is subtracted because we want to count 0 in)
Now, let's say you want to store negative numbers too. How can we achieve that? We can dedicate one bit for sign. If this bit is
0 then we interpret other 7 bits as a positive number, otherwise as a negative number. It's best to use most significant bit for sign because it makes some operations easier.
Why is two's complement the best?
Note that if we dedicate most significant bit for sign bit, then we can't convert number to binary without knowing how many bits we will need. For example is we have 4 bits, then the number -5 in trivial approach is
1101 , on 7 bits it would be 1000101 . 0001101 (4-bit -5 padded with zeros to 7 bits length) is actually 13 (most significant bit is 0, so it's positive).
I won't do the homework for you, but I can give you general tips:
To convert
|
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |