Help: Bit manipulation with VB 4.0
Author Message
Help: Bit manipulation with VB 4.0

where you can use the shift operator to mask for the specific bit you are
looking for.  I need to be able to mask off the high-order 6 bits to one
variable while retaining the lower order 2 bits for another variable.

Any help would really be appreciated.

Thanks,
Shawn.

Fri, 22 Jan 1999 03:00:00 GMT
Help: Bit manipulation with VB 4.0

Quote:
>where you can use the shift operator to mask for the specific bit you are
>looking for.  I need to be able to mask off the high-order 6 bits to one
>variable while retaining the lower order 2 bits for another variable.

>Any help would really be appreciated.

>Thanks,
>Shawn.

Wouldn't
H% = ( Var% AND &b11111100 ) \ 4
L% = ( Var% AND &b00000011 )
work?

____    _    ____      ____  _____
|  _ \  / \  / ___) __ | ___)(_   _) | Don Schullian
| |_)  / _ \ \____\/  \|  _)   | |   |  Gramou 33
|____//_/ \_\(____/\__/|_|     |_|   |  Papagou, 156-69
___________________________________  |  Greece
=================================== |  ++30-1-654-6200

Nutz 'n Boltz for powerbasic v3.2
A library of everyday goodies

Fri, 22 Jan 1999 03:00:00 GMT
Help: Bit manipulation with VB 4.0

-> used to C where you can use the shift operator to mask for the
-> specific bit you are looking for.  I need to be able to mask off the
-> high-order 6 bits to one variable while retaining the lower order 2
-> bits for another variable.

LoBits = Byte AND 3 'lowest two bits
HiBits = Byte AND NOT 3 'third and higher bits

You can use AND to mask off whatever bits you want. If needed, you can
multiply or divide by powers of two to shift left or right. Look up the
Boolean operators, AND, OR, XOR (or EOR) and NOT.

dow

Fri, 22 Jan 1999 03:00:00 GMT
Help: Bit manipulation with VB 4.0

Quote:

> where you can use the shift operator to mask for the specific bit you are
> looking for.  I need to be able to mask off the high-order 6 bits to one ...

The high order bits of *what*? An 8-bitter, a 16-bitter, a 32-bitter?

Quote:
> variable while retaining the lower order 2 bits for another variable.
> [ >8 ]

Dim thing As Long
Dim v1 As Long
Dim v2 As Long

v0 = (thing & 0xFC000000)      ' yields most significant 6 bits of a Long
v1 = (thing & 0xFC000000) / 0x04000000 ' moves top 6 bits into bottom
or perhaps
v0 = (thing And 0xFC) / 0x04   ' yields 0 ... 63
v1 = (thing And 0x03)          ' yields 0 ... 3
You pays yer money ...

--

Vox (0|+44)1642 216 200      |     |     |   Zetland Buildings, Exchange Square
Fax (0|+44)1642 216 201      o     o     *   Middlesbrough, Cleveland.  TS1 1DE
-- "I don't know much about quantum electrodynamics, but I know what I like" --

Sun, 24 Jan 1999 03:00:00 GMT
Help: Bit manipulation with VB 4.0

Quote:

>where you can use the shift operator to mask for the specific bit you are
>looking for.  I need to be able to mask off the high-order 6 bits to one
>variable while retaining the lower order 2 bits for another variable.
>Any help would really be appreciated.
>Thanks,
>Shawn.

So whats wrong with

HWReg = HWReg And &H7F

RTFM Bitwise Operators...
__   __   _______________________________
//)) //)) | Richard RUDEK. MicroDek.      | Hey, Whadda ya
//\\ //\\  | Chatswood, Sydney. Australia. | want for nuting...
`-------------------------------'

Sun, 24 Jan 1999 03:00:00 GMT
Help: Bit manipulation with VB 4.0

Quote:

>where you can use the shift operator to mask for the specific bit you are
>looking for.  I need to be able to mask off the high-order 6 bits to one
>variable while retaining the lower order 2 bits for another variable.

>Any help would really be appreciated.

Can't you AND, OR, NOT, etc. in Visual Basic?  You can do bit
manipulation in basic, it's just that the way it appears on the screen is
different.  The results are the same.