CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

24 bits ints!

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Laurent chouinard
Guest







24 bits ints!
PostPosted: Fri Feb 28, 2003 7:37 am     Reply with quote

<font face="Courier New" size=-1>I know i know, i'm demanding... But I feel like saving RAM space, and I would require 24 bit integers for data storage. Would anyone have an idea about how to achieve that?

So far, i got this method which isn't really pretty:


int32 temp;
int8 final_low, final_mid, final_high;

temp = 1294387;
final_low = make8(temp,0);
final_mid = make8(temp,1);
final_high= make8(temp,2);

//later that day...

temp = make32(0,final_high, final_mid, final_low);


Seems to me this approach is quite bulky and cpu intensive, especially since i'm already maxing out my ROM (I've got several hundred bytes free to work with).</font>
___________________________
This message was ported from CCS's old forum
Original Post ID: 12212
chas
Guest







Re: 24 bits ints!
PostPosted: Fri Feb 28, 2003 9:54 am     Reply with quote

:=<font face="Courier New" size=-1>I know i know, i'm demanding... But I feel like saving RAM space, and I would require 24 bit integers for data storage. Would anyone have an idea about how to achieve that?
:=
:=So far, i got this method which isn't really pretty:
:=
:=
:=int32 temp;
:=int8 final_low, final_mid, final_high;
:=
:=temp = 1294387;
:=final_low = make8(temp,0);
:=final_mid = make8(temp,1);
:=final_high= make8(temp,2);
:=
:=//later that day...
:=
:=temp = make32(0,final_high, final_mid, final_low);
:=
:=
:=Seems to me this approach is quite bulky and cpu intensive, especially since i'm already maxing out my ROM (I've got several hundred bytes free to work with).</font>

Maybe there's a way to use the old struct/union trick to help you out??

struct sbytes
{
int low_byte;
int mid_byte;
int high_byte;
int extra_byte;
};

union udouble
{
int32 int32_temp;
struct sbytes stemp;
} double_temp;

This uses only 4 bytes of ram and you can read or write as a 32 bit int and then read or write each byte individually. You could also try creating a 3 byte structure and add it to the union definition to handle your int24s and copy them in and out of the 32 bit structure??

Just an idea. (Thanks again Hans W.)
___________________________
This message was ported from CCS's old forum
Original Post ID: 12221
R.J.Hamlett
Guest







Re: 24 bits ints!
PostPosted: Fri Feb 28, 2003 11:21 am     Reply with quote

:=<font face="Courier New" size=-1>I know i know, i'm demanding... But I feel like saving RAM space, and I would require 24 bit integers for data storage. Would anyone have an idea about how to achieve that?
:=
:=So far, i got this method which isn't really pretty:
:=
:=
:=int32 temp;
:=int8 final_low, final_mid, final_high;
:=
:=temp = 1294387;
:=final_low = make8(temp,0);
:=final_mid = make8(temp,1);
:=final_high= make8(temp,2);
:=
:=//later that day...
:=
:=temp = make32(0,final_high, final_mid, final_low);
:=
:=
:=Seems to me this approach is quite bulky and cpu intensive, especially since i'm already maxing out my ROM (I've got several hundred bytes free to work with).</font>

You can work with 24bit variables. :-)
typedef struct {
int8 lobyte;
int8 midbyte;
int8 hibyte;
} int24word;

union int24 {
int24word word;
int8 b[3];
}my_variable;

my_variable.word=1294387l;

//You can also access the individual bytes using:
my_variable.b[0], my_variable.b[1] & my_variable.b[2]

This reserves only 24bits of storage, whereas using a int32, will reserve 32bits.

Best Wishes
___________________________
This message was ported from CCS's old forum
Original Post ID: 12225
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group