Skip to main content
gamedev.net
🔒 Locked

extracting bits

Started by angry Nov 22, 2003 at 11:18 AM 0 replies 250+ views
Original Post
angry
angry
Let''s say I have a unsigned char where the first bit is a flag then the following 6 bits are some number and the last bit is another flag. How would I extract these values into separate variables?
C-Junkie
C-Junkie
two possibilities...

struct {
char a: 1;
char b: 6;
char c: 1;
};

or

a = orig>>7 & 1;
b = orig>>6 & 63;
c = orig & 1;

Topic Locked

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

Sign in to reply to this topic.