Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Two's Complement Help.

Status
Not open for further replies.
To create the two's complement:

Write it out as a binary number ( 0 0 0 0 1 0 1 0 )

Invert all the bits

Add 1

You now have the twos complement, convert back to hex if required.

JimB
 
To create the two's complement:

Write it out as a binary number ( 0 0 0 0 1 0 1 0 )

Invert all the bits

Add 1

You now have the twos complement, convert back to hex if required.

JimB

A clear answer perfectly understood.

Thanks for your help.
 
my maths is not good we dont do much maths in school and dont do binary or hex but i am interested in learning this stuff so can you tell me if i got this write using your example please "(00001010)" so this inverted is 11110101?? is that right?? and adding 1 to it makes it 11110110??? and convert to hex (on the calculator) makes it f6??
do i have that correct?? one last question and i know its stupid but whats 2's compliment??
logan
 
Hey Logan,

You are correct. As you probably discovered, invert means to switch 0 to 1, or vice verse. Here are the series of steps:

Step 1: Record First Value:
Code:
0 0 0 0 1 0 1 0

Step 2: Invert:
Code:
1 1 1 1 0 1 0 1

Step 3: Add 1:

Code:
1 1 1 1 0 1 1 0

In binary, you increment in doubles reversely, thus:

Code:
128, 64, 32, 16, 8, 4, 2, 1

So if you examine the red portion in step 2:
Code:
1 1 1 1 0 1 [COLOR="Red"]1 0[/COLOR]

You will notice that the '1' is in the 1's value, so adding another 1 would put it in the 2's place.

one last question and i know its stupid but whats 2's compliment??

It's what I just showed you. Although I think you are referring to why it is used? The answer is fun of course! ;)

I only know it, but I haven't used it for anything. I'm sure others would be able to tell you applications.
 
2's compliment is a good way for expressing numbers that are negative or positive.

It is often used on Centigrade temperature sensors that cover ranges like -55º to +125º C.

One way of looking at 2's compliment is that the most significant digit represents minus what it would represent in binary. An 8 bit temperature would have bits that represent
-128º C
64º C
32º C
16º C
8º C
4º C
2º C
1º C
 
can you tell me if i got this write using your example please
"(00001010)" so this inverted is 11110101?? is that right?? Yes, this is also known as the 1's complement

and adding 1 to it makes it 11110110??? and convert to hex (on the calculator) makes it f6??
do i have that correct?? Yes. correct again

one last question and i know its stupid but whats 2's compliment??

As others have said, the 2's complement is a way of writing negative numbers in binary.
So, the original hex number 0x0A which is equivalent to 10 in decimal has been converted to the hex equivalent of -10 in decimal.

And just as 10 + (-10) = 0 in decimal, so a binary number added to its 2's complement is also zero.

As a side issue, at the machine level, computers work in binary.
For us humans trying to remember binary numbers is a real pain (at least it is for me!), so hexadecimal is just a convenient way of remembering and writing binary numbers.

JimB
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top