Go to Post I've got it! INFLATABLE clown fish!!!! - dlavery [more]
Home
Go Back   Chief Delphi > Other > Math and Science
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 14-01-2007, 22:15
Michael Hill's Avatar
Michael Hill Michael Hill is offline
Registered User
FRC #3138 (Innovators Robotics)
Team Role: Mentor
 
Join Date: Jul 2004
Rookie Year: 2003
Location: Dayton, OH
Posts: 1,567
Michael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond repute
Negatives in Binary

I'm reading a book on Fortran 90/95 right now, and I was wondering, in general math, how would you go about making a binary number negative without a given bit length? For example, how would I know 1110111101 was -67 rather than 957? I remember something about the leftmost bit being 1, it's negative, and if it's 0, it's positive. But how would I know if 1011 is 11 or -5?
Reply With Quote
  #2   Spotlight this post!  
Unread 14-01-2007, 22:25
Phalanx's Avatar
Phalanx Phalanx is offline
Formerly Team 1089 (Mercury)
AKA: Michael Reffler
FRC #5431 (Titan Robotics)
Team Role: Mentor
 
Join Date: Jun 2005
Rookie Year: 1999
Location: Lewisville, TX (previously NJ)
Posts: 384
Phalanx has a reputation beyond reputePhalanx has a reputation beyond reputePhalanx has a reputation beyond reputePhalanx has a reputation beyond reputePhalanx has a reputation beyond reputePhalanx has a reputation beyond reputePhalanx has a reputation beyond reputePhalanx has a reputation beyond reputePhalanx has a reputation beyond reputePhalanx has a reputation beyond reputePhalanx has a reputation beyond repute
Re: Negatives in Binary

Yes, when the "high order" bit is on it is a negative number, but it doesn't have to be. It depends on your code and what you wish to do with the value or how you wish to treat it.

As for a given bit length it is always in terms of the field type. a byte = 8 bits with high bit as sign bit, a word = 16 bits again high bit is the sign bit, and so on.

I hope this helps.
__________________
Don't just ask the experts, become one!
Leadership is not about ability. It's about responsibility!
Diagonally Parked in a Parallel Universe. It's okay we do Quantum Physics


Reply With Quote
  #3   Spotlight this post!  
Unread 14-01-2007, 22:29
Michael Hill's Avatar
Michael Hill Michael Hill is offline
Registered User
FRC #3138 (Innovators Robotics)
Team Role: Mentor
 
Join Date: Jul 2004
Rookie Year: 2003
Location: Dayton, OH
Posts: 1,567
Michael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond repute
Re: Negatives in Binary

So the biggest and smallest numbers allowed in a byte are 255 and -256? what would I do if I wanted to convert the number 3485 to binary?
Reply With Quote
  #4   Spotlight this post!  
Unread 14-01-2007, 22:30
something something is offline
Registered User
FRC #1438
 
Join Date: Mar 2004
Rookie Year: 2004
Location: Cypress, CA
Posts: 10
something is an unknown quantity at this point
Re: Negatives in Binary

Quote:
Originally Posted by Michael Hill View Post
But how would I know if 1011 is 11 or -5?
A signed 4-bit value would only be able to represent values from 4 to -4. Check out two's complement on wikipedia for more info on binary representations of negative numbers.
Reply With Quote
  #5   Spotlight this post!  
Unread 14-01-2007, 22:33
Michael Hill's Avatar
Michael Hill Michael Hill is offline
Registered User
FRC #3138 (Innovators Robotics)
Team Role: Mentor
 
Join Date: Jul 2004
Rookie Year: 2003
Location: Dayton, OH
Posts: 1,567
Michael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond repute
Re: Negatives in Binary

OOH! so a number 8 bits long will indicate if it is negative or positive by the left-most bit? so by default a number is 8 bits?
Reply With Quote
  #6   Spotlight this post!  
Unread 14-01-2007, 22:48
Phalanx's Avatar
Phalanx Phalanx is offline
Formerly Team 1089 (Mercury)
AKA: Michael Reffler
FRC #5431 (Titan Robotics)
Team Role: Mentor
 
Join Date: Jun 2005
Rookie Year: 1999
Location: Lewisville, TX (previously NJ)
Posts: 384
Phalanx has a reputation beyond reputePhalanx has a reputation beyond reputePhalanx has a reputation beyond reputePhalanx has a reputation beyond reputePhalanx has a reputation beyond reputePhalanx has a reputation beyond reputePhalanx has a reputation beyond reputePhalanx has a reputation beyond reputePhalanx has a reputation beyond reputePhalanx has a reputation beyond reputePhalanx has a reputation beyond repute
Re: Negatives in Binary

Quote:
Originally Posted by Michael Hill View Post
OOH! so a number 8 bits long will indicate if it is negative or positive by the left-most bit? so by default a number is 8 bits?
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.
__________________
Don't just ask the experts, become one!
Leadership is not about ability. It's about responsibility!
Diagonally Parked in a Parallel Universe. It's okay we do Quantum Physics


Reply With Quote
  #7   Spotlight this post!  
Unread 14-01-2007, 22:59
ChuckDickerson's Avatar
ChuckDickerson ChuckDickerson is offline
Mentor / Bayou & CMP Division LRI
FRC #0456 (Siege Robotics)
Team Role: Mentor
 
Join Date: May 2004
Rookie Year: 2004
Location: Vicksburg, MS
Posts: 877
ChuckDickerson has a reputation beyond reputeChuckDickerson has a reputation beyond reputeChuckDickerson has a reputation beyond reputeChuckDickerson has a reputation beyond reputeChuckDickerson has a reputation beyond reputeChuckDickerson has a reputation beyond reputeChuckDickerson has a reputation beyond reputeChuckDickerson has a reputation beyond reputeChuckDickerson has a reputation beyond reputeChuckDickerson has a reputation beyond reputeChuckDickerson has a reputation beyond repute
Re: Negatives in Binary

An UNSIGNED byte can represent a value between 0 and 255.
A SIGNED byte can represent -128 to 127.

You must know what type of byte you are working with. This is the whole purpose of declaring variable types.
Reply With Quote
  #8   Spotlight this post!  
Unread 14-01-2007, 23:03
Michael Hill's Avatar
Michael Hill Michael Hill is offline
Registered User
FRC #3138 (Innovators Robotics)
Team Role: Mentor
 
Join Date: Jul 2004
Rookie Year: 2003
Location: Dayton, OH
Posts: 1,567
Michael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond repute
Re: Negatives in Binary

wow, things are becoming clear to me now in declaring variable types. before, I'd never really cared about it (mostly because I was doing stuff where declaring variable types weren't required such as programming a calculator and MatLAB). Thanks
Reply With Quote
  #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
  #10   Spotlight this post!  
Unread 14-01-2007, 23:12
Phalanx's Avatar
Phalanx Phalanx is offline
Formerly Team 1089 (Mercury)
AKA: Michael Reffler
FRC #5431 (Titan Robotics)
Team Role: Mentor
 
Join Date: Jun 2005
Rookie Year: 1999
Location: Lewisville, TX (previously NJ)
Posts: 384
Phalanx has a reputation beyond reputePhalanx has a reputation beyond reputePhalanx has a reputation beyond reputePhalanx has a reputation beyond reputePhalanx has a reputation beyond reputePhalanx has a reputation beyond reputePhalanx has a reputation beyond reputePhalanx has a reputation beyond reputePhalanx has a reputation beyond reputePhalanx has a reputation beyond reputePhalanx has a reputation beyond repute
Re: Negatives in Binary

No, it doesn't matter what the language is, the representation is identical.

Fortran, Cobol, C, PL/1, Pascal, APL, ect... it's all the same internally.
__________________
Don't just ask the experts, become one!
Leadership is not about ability. It's about responsibility!
Diagonally Parked in a Parallel Universe. It's okay we do Quantum Physics


Reply With Quote
  #11   Spotlight this post!  
Unread 15-01-2007, 00:24
eugenebrooks eugenebrooks is offline
Team Role: Engineer
AKA: Dr. Brooks
no team (WRRF)
 
Join Date: Jan 2004
Rookie Year: 2001
Location: Livermore, CA
Posts: 601
eugenebrooks has a reputation beyond reputeeugenebrooks has a reputation beyond reputeeugenebrooks has a reputation beyond reputeeugenebrooks has a reputation beyond reputeeugenebrooks has a reputation beyond reputeeugenebrooks has a reputation beyond reputeeugenebrooks has a reputation beyond reputeeugenebrooks has a reputation beyond reputeeugenebrooks has a reputation beyond reputeeugenebrooks has a reputation beyond reputeeugenebrooks has a reputation beyond repute
Re: Negatives in Binary

The posts in this thread have so many errors that I am not
going to try and correct them all. I would suggest that you
download and read Chapter 6 of
http://srvhsrobotics.org/eugenebrooks/IntroCProg.pdf

There are 10 kinds of people in the world, those who
understand binary, and those who don't...

Have fun,
Eugene
Reply With Quote
  #12   Spotlight this post!  
Unread 10-02-2007, 15:18
sdexp's Avatar
sdexp sdexp is offline
Imploding Piston
AKA: Sumit Dutta
FRC #1111 (Powerhawks)
Team Role: Leadership
 
Join Date: Jan 2005
Rookie Year: 2003
Location: MD
Posts: 28
sdexp is on a distinguished road
Send a message via MSN to sdexp
Re: Negatives in Binary

1111 = our team number = 15

100000000 = 256
10000000 = 128
__________________
.: Sumit Dutta :.

2004RobotExcitement * 2004RobotQuality = 2005RobotExcitement * 2005RobotQuality = 2006RobotExcitement * 2006RobotQuality = 2007RobotExcitement * 2007RobotQuality
Due to Conservation of Madness

South River High School Robotics
Team 1111
Powerhawks

Last edited by sdexp : 10-02-2007 at 15:20.
Reply With Quote
  #13   Spotlight this post!  
Unread 10-02-2007, 21:28
TimCraig TimCraig is offline
Registered User
AKA: Tim Craig
no team
 
Join Date: Aug 2004
Rookie Year: 2003
Location: San Jose, CA
Posts: 221
TimCraig is a splendid one to beholdTimCraig is a splendid one to beholdTimCraig is a splendid one to beholdTimCraig is a splendid one to beholdTimCraig is a splendid one to beholdTimCraig is a splendid one to beholdTimCraig is a splendid one to behold
Re: Negatives in Binary

Quote:
Originally Posted by something View Post
A signed 4-bit value would only be able to represent values from 4 to -4. Check out two's complement on wikipedia for more info on binary representations of negative numbers.
Actually, 4 bits provides 16 possible combinations of 0 and 1 so it can represent 0 to 15 as an unsigned integer or -8 to +7 as a signed integer.
(unsigned integer in this case being a mathematical term rather than the C type).

Yes, typically computers represent signed integers as two's complement so negative numbers have the high bit set.
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Refrain from the negatives Arefin Bari General Forum 19 10-05-2006 22:43
Reading binary data from a file and writing it in VB complete Programming 1 02-01-2006 21:21
binary in C sciguy125 Programming 9 13-11-2005 22:12
Binary in Rose is Rose MisterX Chit-Chat 8 11-02-2004 18:26
delphi: binary sort archiver 2000 0 24-06-2002 00:30


All times are GMT -5. The time now is 12:11.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi