• Status: Solved
• Priority: Medium
• Security: Public
• Views: 832

# Bit shifting...

What's the best method of bit shifting in VB6?
I'm unable to find any methods to do the job so assume a bit of work is required. I need to be able to shift the bits by a set amount.
0
lbowers
1 Solution

Commented:
for bit wise operation use And Operator
Eqv,imp, Not,Or,Xor operators as below. Use the same to implement the shift
MyCheck = A And B
0

Commented:
Don't forget integer divide \

AND won't *shift* bits. You've got to declare 'em integers and multiply by 2/4/8, etc. to implement shift lefts and you can do integer divide by 2/4/8 etc. for shift right.

M

0

Author Commented:
AND doesn't shift - It just selectively removes bits.
Thanks anyway.
0

Commented:
0

Commented:
here is an example...

public bit(1 to 8) as byte

bit(1)=1:bit(2)=2:bit(3)=4:bit(4)=8:bit(5)=16:bit(6)=32:bit(7)=64:bit(8)=128

.......

function SHR(num as byte, bits as byte)
SHR = num / bit(bits)
end function

function SHL(num as byte, bits as byte)
SHL = num * bit(bits)
end function

that's about it, for a simply byte...

..-=ViKtOr=-..
0

Commented:
opps ;-))

bit(1)=1:bit(2)=2:bit(3)=4:bit(4)=8:bit(5)=16:bit(6)=32:bit(7)=64:bit(8)=128

should be replaced with the following :)

bit(1)=2:bit(2)=4:bit(3)=8:bit(4)=16:bit(5)=32:bit(6)=64:bit(7)=128:bit(8)=256

sorry for the inconvenience.. ;-)

..-=ViKtOr=-..
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.