Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


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

Posted on 1999-06-30
Medium Priority
Last Modified: 2006-11-17
I want switch an Integer Value with low byte and high byte.
But I can't find "shift" or "bitwise and" command.
Question by:cchi
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
LVL 10

Accepted Solution

caraf_g earned 200 total points
ID: 1521026
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


Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question