Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Stardust

having two separate values in one long

This topic is 5706 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi! (C++) I have a long and I would like to store one 4 bit value and one 16bit value in it and then be able to get the two values back by just reading the bits. how would I do this? something like this I guess... char cValue = 50; int iValue = 12000; long lValue; // the & is just for showing, I''m trying to find the // specific character to use but I havn''t found it... lValue&31 = cValue&3; lValue&30 = cValue&2; lValue&29 = cValue&1; lValue&28 = cValue&0; lValue&15 = iValue&15; ... what is the character to use? or is there a better method to do this? thanks!

Share this post


Link to post
Share on other sites
Advertisement
Don''t know how you''re reading-in the long, but depending on where the bytes align something like this could work:

  
union PackedLong
{
unsigned long l;
struct
{
unsigned long v4 : 4;
unsigned long v16 : 16;
};
};

You can pack the unused bits with unused bitfield lengths.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!