Shop OBEX P1 Docs P2 Docs Learn Events
What is the largest number that can be represented by a "word: — Parallax Forums

What is the largest number that can be represented by a "word:

realolman1realolman1 Posts: 55
edited 2017-01-11 17:46 in Propeller 1
The title pretty much asks my question
I am thinking that I can go from 0-255 with a byte

Is it 65535?
I want an array with elements from 0-1440 .. the number of minutes in 24 hours, so I need a "word" ...is that correct?
word  AnalogRecord[NumberRecords] 
thank you

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2017-01-11 17:41
    Correct. :nerd:

    You'll also be using only 11 bits of the word, so if you wanted to you could use the other 5 bits for flags or status indicators for events and pack that information within the stored value.

  • the more I think of this, maybe it is not as simple as I thought... I want an array of 1440 elements... all the values in the array will be between 0 -500 (ADC voltage conversions)


    Suppose I wanted an array of 1440 elements, that the values were all above 66,000... how do I go about declaring this array?


  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    Well, you could declare an array of longs. These would be 32-bits each.
  • My first question to you is 6600 is the lowest number, what is the highest?
    Jim
  • ...or you could store all the values with 66,000 subtracted from them, and add that offset back in when you use them.
      'store a value
      AnalogRecord[index] := Reading - 66000
    
      'read it back
      Reading := AnalogRecord[index] + 66000
    

    Storing an array of longs would be the simplest approach, but it wastes space. If you don't need full precision, you could store your ADC results divided by two into an array of bytes. Since your source number is only 0 to 500, half that is 0 to 250 which fits into a byte. If you're running low on memory you can trade off speed or resolution to gain memory.
  • those are very interesting possibilities ... thank you for the ideas
Sign In or Register to comment.