What does this mean?

Put your programming skills to the test in these challenges.

What does this mean?

Post by ghostheadx2 on Wed Jun 03, 2015 4:31 pm
([msg=88315]see What does this mean?[/msg])

I was trying to understand bytes better and I came across this page and wanted to understand the term "signed two's complement integer."

What does "two's" mean in this case because I don't get it?

:|
ghostheadx2
Contributor
Contributor
 
Posts: 728
Joined: Wed Nov 19, 2014 1:19 am
Blog: View Blog (0)


Re: What does this mean?

Post by ghost107 on Wed Jun 03, 2015 7:44 pm
([msg=88317]see Re: What does this mean?[/msg])

Representing the number in binary, it has a parity bit that will represent the sign value(the first bit is the sign bit 0 = positive, 1= negative).
This means since a byte has 8 bits, the values it can take is max 2 at the power of 7(128 values), which are the first 7 bits, where the last bit is the sign.

Code: Select all
from 0 to 127       = 0000 0000 - 0111 1111
from (-128) to (-1) = 1000 0000 - 1111 1111
User avatar
ghost107
Poster
Poster
 
Posts: 321
Joined: Wed Jul 02, 2008 7:57 am
Blog: View Blog (0)


Re: What does this mean?

Post by ghostheadx2 on Wed Jun 03, 2015 8:28 pm
([msg=88319]see Re: What does this mean?[/msg])

Aah. I see. So the ASCII character in base 127 represents the same number in binary. so that means nul is zero and whatever the next number in ASCII is is 10. Then the third word means 11 or 3, etc.?
ghostheadx2
Contributor
Contributor
 
Posts: 728
Joined: Wed Nov 19, 2014 1:19 am
Blog: View Blog (0)


Re: What does this mean?

Post by ghost107 on Thu Jun 04, 2015 7:39 pm
([msg=88337]see Re: What does this mean?[/msg])

Its more about the sign:
The ones complement is the number in binary with inverted bits ( 1 = 001 and -1 = 110)
Code: Select all
Bin    S   U
000 =  0 = 0
001 =  1 = 1
010 =  2 = 2
011 =  3 = 3
100 = -3 = 4
101 = -2 = 5
110 = -1 = 6
111 = -0 = 7


The Two's complement is the ones complement+1( -1 = ~001+1 = 110+1 = 111), which eliminates the need of having two 0
Code: Select all
Bin    S   U
000 =  0 = 0
001 =  1 = 1
010 =  2 = 2
011 =  3 = 3
100 = -4 = 4
101 = -3 = 5
110 = -2 = 6
111 = -1 = 7
User avatar
ghost107
Poster
Poster
 
Posts: 321
Joined: Wed Jul 02, 2008 7:57 am
Blog: View Blog (0)



Return to Programming

Who is online

Users browsing this forum: No registered users and 0 guests