View Single Post
  #4   Spotlight this post!  
Unread 19-02-2003, 20:03
ChrisA's Avatar
ChrisA ChrisA is offline
Registered User
#0857 (Superior Roboworks)
Team Role: College Student
 
Join Date: Feb 2002
Location: Michigan Tech
Posts: 157
ChrisA is on a distinguished road
Send a message via AIM to ChrisA
Re: Re: loops inside of subs???

Quote:
Originally posted by Joel J.
A byte can store a number no larger than 254. After that it loops around to a negative number (an illusion).
Unfortunately this is not the case. It can hold a number between 0 and 255 (256 values). If you have 255 and add one to it you will get 0. When you add 1 to 1 in binary you get 10. The 0 appears and the 1 is carried over to the next slot. So when you have 11111111 and you add 1 to it all 8 values turn to 0 and the 1 is carried over into the next available space. In this case there is no space left so it is simply dropped leaving you with 00000000.

[edit]As previously stated, MyCounter is a byte which can never reach 3001. As hard as the processor tries, it can never continuously add numbers to a byte and reach 3001. The byte will reach 255 and then drop back to 0 and then repeat which causes an infinite loop. there is no problem with running that loop where you have it. Try using a word (2 bytes stuck together) instead of a byte. If what rbayer says is true then you will never be able to do a loop for that long anyways, but I don't think there is any harm in trying it.[/edit]
__________________
Programmer
----------------
Team#857
Superior Roboworks

WildStang Alum

Last edited by ChrisA : 19-02-2003 at 20:12.