Results 1 to 16 of 16

Thread: [RESOLVED] Bit conversion operations

Threaded View

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2009
    Posts
    629

    Resolved [RESOLVED] Bit conversion operations

    Hello everyone.

    In my API class I encountered a lot of times I had to Get/Set low/high order <something> of <something>. For example, get the low order integer from a long. I made a few functions for this:

    Code:
        Public Shared Function LHByteCombine(ByVal low As Byte, ByVal high As Byte) As Short
            Return low + high * 2 ^ 8
        End Function
        Public Shared Function LHShortCombine(ByVal low As Short, ByVal high As Short) As Integer
            Return low + high * 2 ^ 16
        End Function
        Public Shared Function LHIntegerCombine(ByVal low As Integer, ByVal high As Integer) As Long
            Return low + high * 2 ^ 32
        End Function
        Public Shared Function GetHighByte(ByVal value As Short) As Byte
            Return value >> 8
        End Function
        Public Shared Function GetHighShort(ByVal value As Integer) As Short
            Return value >> 16
        End Function
        Public Shared Function GetHighInteger(ByVal value As Long) As Integer
            Return value >> 32
        End Function
        Public Shared Function GetLowByte(ByVal value As Short) As Byte
            Return value - GetHighByte(value) * 2 ^ 8
        End Function
        Public Shared Function GetLowShort(ByVal value As Integer) As Short
            Return value - GetHighShort(value) * 2 ^ 16
        End Function
        Public Shared Function GetLowInteger(ByVal value As Long) As Integer
            Return value - GetHighInteger(value) * 2 ^ 32
        End Function
    Before I start using these functions permanently, I come to ask if it contains any bugs, especially because of the Unsigned/Signed issue.

Posting Permissions

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



Click Here to Expand Forum to Full Width