Extract Binary Data From Word Value
Posted: Sun Mar 12, 2006 8:31 pm
I'm trying to extract integer values from a Binary Sequence.
For Example.
Say We have the Number 26458 in binary this looks like
110011101011010
I need to seperate the binary data into 3 Chunks each of five ex.
11001 11010 11010
This then needs to convert to
25, 26, 26 the integer values of each set of 5 binary digits.
I know I could use the bin() function but speed is critcal for this operation. My guess is that some of the bitshifting operators is the key... but I just don't get it.
Any help would be appreciated.
The reason I need this is because I need to extract the color values out of a 16bit color image. This is how its stored.
Bit 1 - Not Used
Bit 2-6 Red
Bit 7-11 Green
Bit 12-16 Blue
THanks is advance.
For Example.
Say We have the Number 26458 in binary this looks like
110011101011010
I need to seperate the binary data into 3 Chunks each of five ex.
11001 11010 11010
This then needs to convert to
25, 26, 26 the integer values of each set of 5 binary digits.
I know I could use the bin() function but speed is critcal for this operation. My guess is that some of the bitshifting operators is the key... but I just don't get it.
Any help would be appreciated.
The reason I need this is because I need to extract the color values out of a 16bit color image. This is how its stored.
Bit 1 - Not Used
Bit 2-6 Red
Bit 7-11 Green
Bit 12-16 Blue
THanks is advance.