Skip to main content
gamedev.net
🔒 Locked

Smaller type

Started by Tai-Pan 2 replies 150+ views
Original Post
Tai-Pan
Tai-Pan
I need to represent LOTS of small records, they must store numbers not higher than 200. Should I use char variables?? "Those who follow the path of the warrior must be ready to die, to stand for their convictions, live for one´s convictions, die for one´s convictions"
"Those who follow the path of the warrior must be ready to die, to stand for their convictions, live for one´s convictions, die for one´s convictions"
Kuladus
Kuladus
u could, or u could use a base 201 numbering system, convert it to decimal to store as an integer, then back again when u need it....though this would be probably a bit too complex for what u need...

according to my calculations u could fit four base 201 numbers into an 32-bit unsigned int... u could make a class like this...


  

class FourRecs
{

int rec;

public:

void setRecord(int number, int indexRec)
{
if (rec!=0)
{
rec %= (201^indexRec);
}
rec += (number * 201^indexRec);
}

int getRecord(int indexRec)
{

return (rec/(201^indexRec));
}

};
Extrarius
Extrarius
Storing 4 base 201 numbers into 32 bits is the same as storing 1 into 8 bits, and the latter is a lot less work. Go with 'char' type variables.

If you could get the former streaming, you would save space eventually, and it would add up if you are storing a lot of them, but I can't remeber how to stream arbitrary base numbers into bytes (if you figure it out, EMAIL ME PLEASE, I need it for a project of mine)

[edited by - Extrarius on March 21, 2003 1:03:49 AM]
"Walk not the trodden path, for it has borne it's burden." -John, Flying Monk
Tai-Pan
Tai-Pan
"..but I can''t remeber how to stream arbitrary base numbers into bytes.."
Sorry but I dont understand what you mean with that: Stream arbitrary base numbers into bytes? Can you explain me?
Thanks

"Those who follow the path of the warrior must be ready to die, to stand for their convictions, live for one´s convictions, die for one´s convictions"
"Those who follow the path of the warrior must be ready to die, to stand for their convictions, live for one´s convictions, die for one´s convictions"

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.