Using byte variable for storing two different values<100 at same time?


Closed Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2013
    Posts
    1,078

    Default Using byte variable for storing two different values<100 at same time?

    Hello.
    I have a project, where I have to store some values in range of 1-99, 100 values total. Planning to use array for that, but since using low end PIC, can't store too many data in array, but maybe it is possible to split array byte somehow? I mean, byte variable can take any value from 1 to 255, but I need to store two values, each in 1-99 range, so maybe it is possible to store two such values in single byte ?

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,516


    Did you find this post helpful? Yes | No

    Default Re: Using byte variable for storing two different values<100 at same time?

    The decimal value 99 requires 7 bits so most you can save by packing values is 1 bit per value with the added overhead and complexity of unpacking them.

    If these values are to be in RAM (which I believe is the case since you mention an array) then I'd say it's not worth the effort but if the values aren't changing and are to be held in "ROM" then, as it happens, the low end PICs have a program memory word size of 14 bits so you could put two 7-bits values into one program memory word.

    /Henrik.

  3. #3
    Join Date
    Feb 2013
    Posts
    1,078


    Did you find this post helpful? Yes | No

    Default Re: Using byte variable for storing two different values<100 at same time?

    Nope, these are pre-defined values, they do not change during program execution, in fact, you gave me good idea, I will flash them to EEPROM during flashing and just use READ statement to read them from corresponding eeprom cell.

Similar Threads

  1. Storing hours and minutes into single byte?
    By CuriousOne in forum mel PIC BASIC Pro
    Replies: 16
    Last Post: - 5th June 2014, 13:28
  2. Word variable and storing correct value
    By Scampy in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 28th December 2012, 13:04
  3. defining max pulsin time with duty cycle 100%
    By hkpatrice in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 5th April 2010, 11:58
  4. 16F877A won't keep relay on 100% of the time
    By coyotegd in forum mel PIC BASIC Pro
    Replies: 20
    Last Post: - 10th September 2007, 12:24
  5. Storing a variable in EEPROM
    By Tissy in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 29th October 2005, 14:53

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts