Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
Solved

# Bit shifting...

Posted on 1999-06-28
Medium Priority
822 Views
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
Question by:lbowers
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points

LVL 6

Expert Comment

ID: 1520311
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

LVL 12

Expert Comment

ID: 1520312
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 Comment

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

LVL 6

Expert Comment

ID: 1520314
0

LVL 10

Accepted Solution

viktornet earned 200 total points
ID: 1520315
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

LVL 10

Expert Comment

ID: 1520316
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

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code thatâ€¦
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can launâ€¦
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process fromâ€¦
###### Suggested Courses
Course of the Month8 days, left to enroll