dcsimg
Results 1 to 7 of 7

Thread: [EXCEL 2003] Circular Shifting

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jun 2008
    Posts
    25

    [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
    Last edited by zbgamer; Jul 21st, 2008 at 10:02 AM.
    Z

  2. #2
    Frenzied Member
    Join Date
    May 2004
    Location
    Carlisle, PA
    Posts
    1,045

    Re: [EXCEL 2003] Circular Shifting

    What datatype are you using / how many bits in your bitfield??? Do you need sign-extension or not???
    Blessings in abundance,
    All the Best,
    & ENJOY!

    Art . . . . Carlisle, PA . . USA

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jun 2008
    Posts
    25

    Re: [EXCEL 2003] Circular Shifting

    integer

    16 bits

    no sign extension
    Z

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Jun 2008
    Posts
    25

    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
    Z

  5. #5
    Frenzied Member
    Join Date
    May 2004
    Location
    Carlisle, PA
    Posts
    1,045

    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
    Last edited by Webtest; Jul 21st, 2008 at 03:32 PM. Reason: Corrected Return variable in 2nd function
    Blessings in abundance,
    All the Best,
    & ENJOY!

    Art . . . . Carlisle, PA . . USA

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Jun 2008
    Posts
    25

    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
    Z

  7. #7
    Frenzied Member
    Join Date
    May 2004
    Location
    Carlisle, PA
    Posts
    1,045

    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.
    Blessings in abundance,
    All the Best,
    & ENJOY!

    Art . . . . Carlisle, PA . . USA

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


Click Here to Expand Forum to Full Width