View Single Post
  #9   Spotlight this post!  
Unread 14-01-2007, 23:06
Noah Kleinberg Noah Kleinberg is offline
Registered User
FRC #0395 (2TrainRobotics)
Team Role: Driver
 
Join Date: Jan 2006
Rookie Year: 2006
Location: New York
Posts: 196
Noah Kleinberg is a splendid one to beholdNoah Kleinberg is a splendid one to beholdNoah Kleinberg is a splendid one to beholdNoah Kleinberg is a splendid one to beholdNoah Kleinberg is a splendid one to beholdNoah Kleinberg is a splendid one to behold
Send a message via AIM to Noah Kleinberg
Re: Negatives in Binary

Quote:
Originally Posted by Phalanx View Post
In essence yes.
For a one byte field the value can be 0-255 if unsigned, or between -127 to +127 if signed.

255 = 1111 1111 (unsigned)
127 = 0111 1111 (unsigned)

-127 = 1111 1111 (signed)
+127 = 0111 1111 (signed)

Again it is about how your code wishes to deal with the field as a signed or unsigned value.
I think that in most cases (maybe it's different in fortran?), the value -127 would be represented by "1000 0001", using two's complement, which is the most common way to represent negative numbers. It's calculated by changing each 1 to a 0 and each 0 to a 1, and then adding 1 to the resulting number (read the wikipedia article linked above for more information...)
Reply With Quote