Originally posted by k1ll3r_x
whats is the process to get the values with this bitwise option, as far as ive searched on the internet all i get is what ever the value is, it gives a number bigger and negative
Bitwise and "~"
~3 <<< what i do is turn this to Binary
0 0 0 0 1 1
and as far as i know all it does it just turns the values arround or somewhat like that and i get "-4" for an ouput, and what i want to know is what is the process, in other words, what is the whole cycle into getting that -4, if anyone can help me, i would really appreciate it, im in a UIL Class and we dont get this for crap...
Bitwise negate or NOT simpy turns teh bits that are on off and teh bits that are off, on.
thus in your example you would have
1 1 1 1 0 0
Mathmatically, the highest bit is negative IF the data is signed. By default I beleive most constants are considered signed in most langauges.
for simplicity I will work with 4 bits, you usually work with 16 or 32, but. I am too lazy.
so if we have a signed 4 bit binary number
0 = 0000
1 = 0001
2 = 0010
3 = 0011
4 = 0100
5 = 0101
6 = 0110
7 = 0111
the last bit has a negative value which makes 1000 equivalent to -8.
Since the other bits are positive numbers, if we have 1001
then we have -8 + 1 which is -7 much taht same way that with 0011 we have 2 + 1.
given 0000 the negate of this is 1111 which is -8 + 7 or -1.
Given 3 is 0011 in binary and you take the negate you get 1100 in binary which is -8 + 4 or -4.