Restored from previous forum. Originally posted by MrVainSCL.
Hi ppl,
if you need any bit of a val (byte), you can use my following procedure for this. I am sure there is a mutch better and faster way using inline asm i.e. - but i am not a x86 asm expert... So this works for the first...

Btw if you know any better and faster way, please let me know...
Thx... happy coding...
Code: Select all
; ------------------------------------------------------------
;
; PureBasic - MyGetBit(val,bitbum) of a byte - Example v1.0
;
; by MrVainSCL! aka Thorsten 21/Dec/2002 PB v3.40+
;
; ------------------------------------------------------------
;
; -----------------------------------
; PROC - MyGetBit()
; -----------------------------------
;
Procedure MyGetBit(val,bitnum) ; val(Byte) bitnum(bit 1-8)
Dim bit.b(8)
;
t1 = val / 2 : If t1*2 <> val : bit(1) = 1 : EndIf ; 222 / 2 = 111 Rest = 0
t2 = t1 / 2 : If t2*2 <> t1 : bit(2) = 1 : EndIf ; 111 / 2 = 55 Rest = 1
t3 = t2 / 2 : If t3*2 <> t2 : bit(3) = 1 : EndIf ; 55 / 2 = 27 Rest = 1
t4 = t3 / 2 : If t4*2 <> t3 : bit(4) = 1 : EndIf ; 27 / 2 = 13 Rest = 1
t5 = t4 / 2 : If t5*2 <> t4 : bit(5) = 1 : EndIf ; 13 / 2 = 6 Rest = 1
t6 = t5 / 2 : If t6*2 <> t5 : bit(6) = 1 : EndIf ; 6 / 2 = 3 Rest = 1
t7 = t6 / 2 : If t7*2 <> t6 : bit(7) = 1 : EndIf ; 3 / 2 = 1 Rest = 1
t8 = t7 / 2 : If t8*2 <> t7 : bit(8) = 1 : EndIf ; 1 / 2 = 0 Rest = 0
;
; -------- If Val = 222, result should be => 11011110 --------
;
result = bit(bitnum)
ProcedureReturn result
EndProcedure
;
; -----------------------------------
;
OpenConsole()
PrintN(Str(MyGetBit(255,8))) ; Get bit number 4 of Val 255 :wink:
Input()
End
;
; ------------------------------------------------------------
PIII450, 256MB Ram, 80GB HD + 6,4 GB, RivaTNT, DirectX8.1, SB AWE64, Win2000 + all Updates...
greetz
MrVainSCL! aka Thorsten