You are here:

C/binary represantation

Advertisement


Question
Respected sir,
what is the binary representation of -1

Answer
In 1's compement or 2's complement!?
How many bits are you talking about - 8 or 16 or 64?

Usually for negative numbers, the leftmost bit will be set.

Usually our computer's follow 2's complement arithmetic for -ve numbers.

So, if you have got -1 in a viriable say (int i):
Take the +ve value of this number( i *= -1;)
Take the complement of the number (i = ~i;)
Add 1 (i++;)
The value you get is -1....
If it is a 16 bit variable, then the binary representation will be FFFF.

-ssnkumar

C

All Answers


Answers by Expert:


Ask Experts

Volunteer


Narendra

Expertise

I can answer questions in C related to programming, data structures, pointers and file manipulation. I use Solaris for doing C code and if you have questions related to C programming on Solaris, I will be able to help better.

Experience

6.5

Organizations belong to
Sun Microsystems

Awards and Honors
Brain Bench Certified Expert C programmer.
Advanced System Software Certified

©2012 About.com, a part of The New York Times Company. All rights reserved.