English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I'm having a hard time understanding binary 1's and 2's complement can anyone explain in detail... please use examples

2007-03-21 17:25:15 · 3 answers · asked by Mithrandir the grey 1 in Computers & Internet Programming & Design

3 answers

This is all to do with how the computer adds and subtracts.

So take a binary number.
0110 - 6 decimal
The left most bit must be 0 for this to work as this is taken as the sign bit. So I can have a number in the range +7 to -8.
The binary number the computer uses is usually larger.

To find the 2s complement you subtract the number from 10000 - 1 binary digit more than all 1s in this instant, will result in 1010 - 10 decimal.

And to use this we do the following.
Now if you take the number 0111 (decimal 7) and add this with the 10 (-6)
you get 10001.
Because we are only interested in 4 bits (binary digits) we lose the extra left most 1 to give the result 0001.
I have just demonstrated the sum 7-6 using addition only.

The computer will probably have a built-in hardware routine to create the complement of a number rather than doing the subtraction.

2007-03-21 23:05:46 · answer #1 · answered by AnalProgrammer 7 · 0 1

answer is comfortable to in what number bits you prefer to save this -2. In Signmagnitude approach: 2's binary code is: 10 As sign is a million, we take sign bit fee as a million If we assume that's saved in 8 bits then -2 would properly be stated as: a million 0000010 sign value 2's supplement approach regulations: 2's supplement of a good type is its sign-value equivalent. To get 2's supplement of a adverse first calculate binary code for its value and supplement and upload a million. Assuming right here additionally 8-bits representation of -2 we prefer. a million. 2s binary code in 8 bits 00000010 2. 1s supplement 11111101 3. upload a million a million consequently -2 turns into: 11111110

2016-12-15 06:00:09 · answer #2 · answered by ? 4 · 0 0

Wiki them, someone else had the same question and a Wiki search gives answer to this; they are representations for negative numbers.

Simply; binary one's comp is just a flip-flop of all binary bits (let's say total_bits) within the bit boundary that the number system on the computer so that all 0 became 1 and 1 be 0, the result is one's comp.

Two's comp. is 2^total_bits - x for the negative number -x.

2007-03-21 17:58:26 · answer #3 · answered by Andy T 7 · 1 0

fedest.com, questions and answers