Negative binary. x_x;;;

Posts 1–9 of 9 · Page 1 of 1
Negative binary. x_x;;;
Alright, so I understand binary numbers and how they work and such. Now, I was just reading up something randomly and came across negative binary numbers.

I understand how it works, and why it's like that.
You basically take the binary number of the positive, and then inverse all the numbers, and add 1 to that number.

What I don't understand is, how it's read... ._.;
For example, let's say we have number 5.
Binary of that is...101.

A negative of that would be = 010+1= 011. I understand usually that it's written in 8 bits. And that's another question. ._.;
Why 8?

So the final of that would be.... 1111 1011. The parts bolded are my questions..
I believe in a signed value the high bit is set when it is negative and 0 when not. I'm not going to claim I am 100% on that but am fairly certain...

Also keep in mind the high bit is n places depending on int8, int16, int32 etc not always bit 8 which would only be true for a int8 (signed byte) in the range of -127 to +127

Anyway what I am getting at for int8:
11111111 = -127
10000001 = -1
10000000 = -0 (0)
00000000 = 0
00000001 = 1
01111111 = 127

Hope that made sense :/

Someone feel free to correct me if I am wrong!
signed byte goes from -127 to 128 I believe
unsigned goes from 0 to 255

at least thats what I think
Maybe BA could shed some light on this ^^
Q: 'Why 8?'
A: Well 8 bits is a byte which is small and easy to work with. but it's not always 8. you could have a 32-bit number that's negative etc. Depends on the hardware etc, but it's easier to manually figure out 8 bits vs 32 or 64

Q: How it's read
A: HD was almost correct in his range assessment; it's -128 to 127. The official name for it is 'Two's Complement' and here's a quick sample
Code:
0 	1 	1 	1 	1 	1 	1 	1 	= 	127
0 	1 	1 	1 	1 	1 	1 	0 	= 	126
0 	0 	0 	0 	0 	0 	1 	0 	= 	2
0 	0 	0 	0 	0 	0 	0 	1 	= 	1
0 	0 	0 	0 	0 	0 	0 	0 	= 	0
1 	1 	1 	1 	1 	1 	1 	1 	= 	−1
1 	1 	1 	1 	1 	1 	1 	0 	= 	−2
1 	0 	0 	0 	0 	0 	0 	1 	= 	−127
1 	0 	0 	0 	0 	0 	0 	0 	= 	−128
Quote Originally Posted by B1ackAnge1 View Post
Q: 'Why 8?'
A: Well 8 bits is a byte which is small and easy to work with. but it's not always 8. you could have a 32-bit number that's negative etc. Depends on the hardware etc, but it's easier to manually figure out 8 bits vs 32 or 64

Q: How it's read
A: HD was almost correct in his range assessment; it's -128 to 127. The official name for it is 'Two's Complement' and here's a quick sample
Code:
0 	1 	1 	1 	1 	1 	1 	1 	= 	127
0 	1 	1 	1 	1 	1 	1 	0 	= 	126
0 	0 	0 	0 	0 	0 	1 	0 	= 	2
0 	0 	0 	0 	0 	0 	0 	1 	= 	1
0 	0 	0 	0 	0 	0 	0 	0 	= 	0
1 	1 	1 	1 	1 	1 	1 	1 	= 	−1
1 	1 	1 	1 	1 	1 	1 	0 	= 	−2
1 	0 	0 	0 	0 	0 	0 	1 	= 	−127
1 	0 	0 	0 	0 	0 	0 	0 	= 	−128
Q: why do they kind of Xor the number when it is negative instead of -1 is just 10000001 ??
Quote Originally Posted by lalakijilp View Post
Q: why do they kind of Xor the number when it is negative instead of -1 is just 10000001 ??
Probably because its minus

-128 = 10000000
-127 = 10000001

So -128 + 1 = -127
10000000 + 00000001 = 10000001

-128+8=-120
10000000 + 00001000 = 10001000
Did not know they counted the high flag in negative values, good to know.
Quote Originally Posted by B1ackAnge1 View Post
Q: 'Why 8?'
A: Well 8 bits is a byte which is small and easy to work with. but it's not always 8. you could have a 32-bit number that's negative etc. Depends on the hardware etc, but it's easier to manually figure out 8 bits vs 32 or 64

Q: How it's read
A: HD was almost correct in his range assessment; it's -128 to 127. The official name for it is 'Two's Complement' and here's a quick sample
Code:
0 	1 	1 	1 	1 	1 	1 	1 	= 	127
0 	1 	1 	1 	1 	1 	1 	0 	= 	126
0 	0 	0 	0 	0 	0 	1 	0 	= 	2
0 	0 	0 	0 	0 	0 	0 	1 	= 	1
0 	0 	0 	0 	0 	0 	0 	0 	= 	0
1 	1 	1 	1 	1 	1 	1 	1 	= 	−1
1 	1 	1 	1 	1 	1 	1 	0 	= 	−2
1 	0 	0 	0 	0 	0 	0 	1 	= 	−127
1 	0 	0 	0 	0 	0 	0 	0 	= 	−128
Ah, this helped alot. Thanks for this.
As for reading them I just need to work on that one, study it more thoroughly I guess.
Thanks guys!
ahh brainfucked LOL!
Posts 1–9 of 9 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Need help?