Results 1 to 4 of 4

Thread: Split Long into two integers (high and low word)

  1. #1

    Thread Starter
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926
    Does somebody have the code to split a long into two integers (the high and the low word)?

    I have got the High Word so far (by integer division by &H10000).

    Even better would be if I could have a hint about how to split an integer. This one is even more difficult. I need bit 0 to 9, and bit 10 to 15 in seperate (integer) variables.

    If anybody could point me in the right direction would be great.

  2. #2
    Addicted Member Geoff Gunson's Avatar
    Join Date
    Jun 1999
    Posts
    241

    Cool

    Hi

    The way I split my 2 byte integers is.

    Low byte:

    LowByte = IntValue And &hFF

    High Byte

    HighByte = (IntValue And &hff00)/ 256

    HTH

    Geoff

  3. #3

  4. #4

    Thread Starter
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926
    Thanks very much, I already figured out how to split the double word into two words. It appears that I don't need to split a word into a 6 and a 10 bit value for the moment, so I will let that rest until needed.
    This is how I did it:

    Code:
    Private Function HW(lngInput As Long) As Integer
    ' returns high word (Bit 16 t/m 31) 
        HW = lngInput \ &H10000
    End Function
    
    Public Function LW(ByVal lngInput As Long) As Integer
    ' returns low word (Bit 0 t/m 15) 
    Dim lngTemp As Long
    Dim blnAddBit As Boolean
        blnAddBit = False
        lngTemp = lngInput And &HFFFF&
        If lngTemp And &H8000& Then
            ' prevent overflow
            lngTemp = lngTemp And &H7FFF
            blnAddBit = True
        End If
    
        If blnAddBit Then lngTemp = (lngTemp Or &H8000)
        LW = CInt(lngTemp)
    End Function

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