1. [EXCEL 2003] Circular Shifting

I have some bitpacked information i need to read in my code, but i need a way to manipulate the binary code. Is there a way to perform circular shifts in VBA? and if there isnt, does anyone have an example of a way to get around this?

Thanks

2. Re: [EXCEL 2003] Circular Shifting

What datatype are you using / how many bits in your bitfield??? Do you need sign-extension or not???

3. Re: [EXCEL 2003] Circular Shifting

integer

16 bits

no sign extension

4. Re: [EXCEL 2003] Circular Shifting

I think i have a method of going around this, but i dont know of any method in VBA that emulates the BIN2DEC/DEC2BIN functiuon

5. Re: [EXCEL 2003] Circular Shifting

There are no native bit shifts or rotates in VBA (that I know of).

This can be optimized, but here is a quick and dirty solution ... signs may get in your way.
Code:
```'16 bit Logical Rotate Left
Function ROL(ByVal aLong As Long) As Long
Dim CarryBit As Boolean

CarryBit = False
If aLong >= 32768 Then
CarryBit = True
aLong = aLong - 32768
End If
aLong = aLong + aLong
If CarryBit Then
aLong = aLong + 1
End If
ROL = aLong

End Function

'16 bit Logical Rotate Right
Function ROR(ByVal aLong As Long) As Long
Dim CarryBit As Boolean

CarryBit = aLong And 1&
If CarryBit Then
aLong = aLong - 1
aLong = aLong + 65536
End If
aLong = aLong / 2
ROR = aLong

End Function```

6. Re: [EXCEL 2003] Circular Shifting

Do you happenb to have anything for converting between Base10 and Base16

im not looking for changing of datatypes or anything though, i just need something that takes the decimal and changes it to binary where both are integers

7. Re: [EXCEL 2003] Circular Shifting

The numbers are identical internally ... it's just a matter of how you display them. I've got to head for home now, but I'll look at it again tomorrow.

Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

Featured