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.
Extract Binary Data From Word Value
Extract Binary Data From Word Value
Derek Gavey
- PB Newbie -
- PB Newbie -
I don't know if the following helps but it certainly strips out the values 25, 26 and 26 from 26458.
Code: Select all
a.w = 26458
low.b = a & %11111
middle.b = a>>5 & %11111
top.b = a >> 10 & %11111
I may look like a mule, but I'm not a complete ass.
Code: Select all
Color = %1100111010110100
Red = (Color & $003E) >> 1
Green = (Color & $07C0) >> 6
Bleue = (Color & $F800) >> 11
Debug Color
Debug bleue
Debug Green
Debug Red
Please correct my english
http://purebasic.developpez.com/
http://purebasic.developpez.com/
- netmaestro
- PureBasic Bullfrog
- Posts: 8452
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
Code: Select all
; SwapRB routine by netmaestro
; useful for importing/exporting colors
; from applications using high-order red
; in the #color (PB colors use high-order blue)
Procedure.l SwapRB(color.l)
tmp=PeekC(@color)
PokeC(@color,PeekC(@color+2))
PokeC(@color+2,tmp)
ProcedureReturn color
EndProcedure
Debug Hex(RGB(128,255,255)) ;high-order blue format
Debug Hex(SwapRB(RGB(128,255,255))) ;high-order red format
BERESHEIT
or
Code: Select all
Red=128
Blue=255
Green=255
Color = red << 16 | Green << 8 | Blue
Debug Hex(COLOR)
Debug Hex(RGB(Blue,Green,Red))
Please correct my english
http://purebasic.developpez.com/
http://purebasic.developpez.com/