Member Avatar for Rahul47

5 in decimal = 0101 in binary.
Its 1's Complement is 1010. Adding 1 to it gives 2's Complement which is 1011. Now 1011 also represents 11 in decimal.

How to differentiate +ve and -ve numbers in Binary ?

It is completely situational. Here is an example:
1000001

What is that number?
If you interpret it as a 7-bit unsigned number you get 65.
If you interpret it as a 7-bit sign/magnitude number you get -1.
If you interpret it as 1's complement you get -63.
If you interpret it as 2's complement you get -64.
If you interpret it as 8-bit 2's complement (very common) you get 65.
If you interpret it as an ASCII character you get 'A'.
If you interpret it as BCD (binary coded decimal) you get 41.

Basically you can represent anything which is countable using only 1s and 0s, and similarly every set of 1s and 0s can represent any number of things. The only way to know which interpretation to use is by situation.

In any given assembly language they will usually tell you exactly what things mean. Incidentally, once you assemble your code in assembly it will be turned into another number. For example in MIPS assembly (as described by my professor) you have:

add $1,$2,$3 = 0000 0000 0100 0011 0000 1000 0010 0000

The key is that n bits can represent 2^n possible 'thing's you need to define what 'thing' you want them to represent. In the case of 1s or 2s complement you just look at the first bit, if it is 1 the number is negative:

1011 in 4 bit 2's complement = -5
1011 in 8 bit 2's complement is 0000 1011 = 11

If you are interested in the topic of representing information I suggest you do some research on information theory, an entire branch of mathematics/computer science devoted to representing, measuring and transmitting information.

commented: Good advice. +15
commented: That was helpful. . . thankx +3
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.