Sampath
Sampath

Reputation: 65988

Bitwise logical operator ~

enter image description here

My question is how it became -6 when do the negation ?

Edit : Let's say like this, if we need to represent 6 on 2's complement it should be 110.But on the 2nd row of above is having '4294967290' (decimal) value when It has been converted by using cal Here So how can it be a -6 then ?

Upvotes: 0

Views: 75

Answers (1)

magdalar
magdalar

Reputation: 141

The negation as you call it is a strict bit inversion, but decimal values in JavaScript are handled as twos-complement.

So you'd basically need '~5 + 1' to get to the equivalent representation as '-5'.

In two's-complement representation, positive numbers are simply represented as themselves, and negative numbers are represented by the two's complement of their absolute value

See http://en.wikipedia.org/wiki/Two's_complement for more details.

Upvotes: 1

Related Questions