How to change an Integer value with low byte and high byte?

I want switch an Integer Value with low byte and high byte.
But I can't find "shift" or "bitwise and" command.
Who is Participating?
caraf_gConnect With a Mentor Commented:
There are no bitwise and shift operators, but you can achieve similar results with:

Dim intX As Integer
Dim intLo As Integer
Dim intHi As Integer
Dim intSwap As Integer

'Try any 4-character hex value. I've tried ABCD, i.e. hi byte is AB, and lo byte is CD. _
 Want to swap hi and lo to get CDAB. _
 You try the same code with a few different values to see the result for yourself - make sure you change the last Msgbox statement too!
intX = &HABCD

intLo = intX And &HFF
intHi = intX And &HFF00

If intLo > 127 Then
    intLo = (intLo - 128) * 256
    intLo = intLo Or &H8000
    intLo = intLo * 256
End If
If intHi < 0 Then
    intHi = intHi And &H7FFF
    intHi = intHi / 256
    intHi = intHi Or &H80
    intHi = intHi / 256
End If

intSwap = intLo Or intHi

'Now check that the lo and hi bytes were swapped.
MsgBox (intSwap = &HCDAB) 'Shows "True" if correct

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.