The &H Notation in Hexadecimal Numbers

By A.J. Bytecode | Created on 2025-09-02 12:58:16

Written with a enthusiastic tone 🤩 | Model: keyless-gpt-4o-mini

0:00 / 0:00

In programming, especially when dealing with low-level operations or interfacing with hardware, hexadecimal numbers are often used. The prefix &H indicates that the number is in hexadecimal format.

What Is Hexadecimal?

Hexadecimal (base 16) uses 16 symbols to represent values: 0-9 for decimal numbers and A-F for additional values (where A = 10, B = 11, C = 12, D = 13, E = 14, and F = 15). For example:

  • &H1 = Decimal 1
  • &H8000 = Decimal 32768

How Does &H Work in Visual Basic (Classic)?

In Visual Basic, hexadecimal numbers prefixed with &H are interpreted as base 16. For instance, &H10 is equivalent to decimal 16, and &H8000 is 32768.

Example: Detecting Key States

The example you provided uses the GetKeyState function to detect whether a key is pressed or not. Here's a breakdown of how it works:

vb Public Const VK_SHIFT = &H10 Dim IsShifted As Boolean IsShifted = (GetKeyState(VK_SHIFT) And &H8000) ' Shift Key

  • VK_SHIFT is defined as &H10, which corresponds to the shift key.
  • The GetKeyState function returns a 16-bit value where:
  • If the high-order bit (most significant bit) is 1, the key is down.
  • If the low-order bit is 1, the key's toggle state (like Caps Lock).

Using &H8000

The value &H8000 in binary is:

1000000000000000

By performing a bitwise AND operation between the result of GetKeyState(VK_SHIFT) and &H8000, you can determine if the shift key is pressed. If the high-order bit in the result is 1, the shift key is down.

Example: Checking ALT + X

Here's how you can check if the user presses the ALT + X keys:

vb Public Const VK_ALT = &H12 Dim IsALT As Boolean IsALT = (GetKeyState(VK_ALT) And &H8000) ' ALT Key tempVKCodeHolder = correctedInputValues(CInt(Trim(HookStruct.vkCode))) ' Translates the keyboard input value to its proper ASCII value. If ((IsALT = True) And (tempVKCodeHolder = 88)) Then Clipboard.Clear Clipboard.SetText(strUserInput) Exit Function End If

  • VK_ALT is defined as &H12.
  • The bitwise AND operation checks if the ALT key is pressed.
  • When both conditions are met (ALT is down and the input character is 'X'), the text from an input box is copied to the clipboard.

Conclusion

The &H notation in hexadecimal numbers is a fundamental concept in programming, especially when working with low-level operations or interfacing with hardware. Understanding how to use hexadecimal numbers and bitwise operations can greatly enhance your ability to write efficient and effective code.



Sources:
- [What are &H1, &H8000, etc.? | Tek-Tips] (https://www.tek-tips.com/threads/what-are-h1-h8000-etc.1080522/)
- [Why does font-size not inherit ? | Tek-Tips] (https://www.tek-tips.com/threads/why-does-font-size-not-inherit.1050326/)
- [Microsoft VBScript runtime error '800a01b6' | Tek-Tips] (https://www.tek-tips.com/threads/microsoft-vbscript-runtime-error-800a01b6.419805/)
- [Send 8-bit data over serial port; values over 3F are being set to 3F] (https://www.tek-tips.com/threads/send-8-bit-data-over-serial-port-values-over-3f-are-being-set-to-3f.1672795/)
- [Moving Aplications to a new screen in C# | Tek-Tips] (https://www.tek-tips.com/threads/moving-aplications-to-a-new-screen-in-c.1416749/)
- [Launch .VBS file from button on HTML page | Tek-Tips] (https://www.tek-tips.com/threads/launch-vbs-file-from-button-on-html-page.931380/)
- [Coverage Paths | Tek-Tips] (https://www.tek-tips.com/threads/coverage-paths.1632312/)
- [Forwarding one internal extension to External number | Tek-Tips] (https://www.tek-tips.com/threads/forwarding-one-internal-extension-to-external-number.1574548/)
- [JOIN from HOLD Files possible? | Tek-Tips] (https://www.tek-tips.com/threads/join-from-hold-files-possible.490981/)
- [SDDPCM query : pcmpath query device | Tek-Tips] (https://www.tek-tips.com/threads/sddpcm-query-pcmpath-query-device-lt-n-gt.1276941/)