Hexadecimal Explained: &H1, &H8000, and Beyond

By The image shows an explanation and example of how to convert a number from base 10 to another base. The image is accompanied by text that explains the concept of hexadecimal numbers and their representation in both base 10 and base 16. It also provides an example of converting the number "16" into hexadecimal format, which would be represented as "&H10". | Created on 2025-08-29 05:26:00

Written with a persuasive tone πŸ—£οΈ | Model: keyless-gpt-o3-mini

0:00 / 0:00
Binary to Hex Conversion

Have you ever encountered lines of code like:


Public Const VK_SHIFT = &H10
IsShifted = (GetKeyState(VK_SHIFT) And &H8000)

If so, you might be wondering what the `&H` symbol means and how it works with numbers like `&H1` and `&H8000`. Let's dive into the world of hexadecimal to find out!

What is Hexadecimal?

Hexadecimal (often abbreviated as "hex") is a base-16 number system. Unlike our everyday decimal system, which uses ten digits (0-9), hex uses sixteen digits: 0-9 and A-F.

The `&H` Prefix

In Visual Basic for Applications (VBA) and other languages, the `&H` prefix is used to denote a number in hexadecimal format. For example:


&H10

This means "εε…­θΏ›εˆΆηš„10" or "16 times 1". In decimal, this equals 16.

Understanding Hexadecimal Numbers

Let's break down the number `&H8000`:


&H8000 = 32768 (in decimal)

This is because in binary, `&H8000` is represented as `1000000000000000`, which is 32768 in decimal. The leading `1` in the binary representation indicates that the high-order bit (signifying a "1" in this case) is set, and the rest of the bits are zero.

Testing Key States with Hexadecimal

The code you provided checks if certain keys are pressed. Let's break down what it does:


IsShifted = (GetKeyState(VK_SHIFT) And &H8000)

`GetKeyState` returns a `SHORT` value, which is 16 bits long. When a key like `VK_SHIFT` is pressed, the high-order bit (the most significant bit) will be set to 1. The code uses bitwise AND to check if this high-order bit is set:


If ((IsAlt = True) And (tempVKCodeHolder = 88)) Then
    Clipboard.Clear
    Clipboard.SetText (strUserInput)
    Exit Function
End If

This checks if both the ALT key (`&H12`) and the "X" key (`88 in decimal or &H58 in hex`) are pressed at the same time. If so, it copies the user's input to the clipboard.

Conclusion

Understanding hexadecimal and how to work with it is crucial for many programming tasks, especially when dealing with low-level operations like checking key states. By breaking down numbers like `&H1` and `&H8000`, we can see that they are simply different ways of representing the same value in a more compact form.

Next time you encounter hexadecimal numbers in your code, you'll know exactly what's going on! Happy coding!



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/)
- [Error: Only content controls are allowed directly in a ... - Tek-Tips] (https://www.tek-tips.com/threads/error-only-content-controls-are-allowed-directly-in-a-content-page.1504551/)
- [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/)
- [Coverage Paths | Tek-Tips] (https://www.tek-tips.com/threads/coverage-paths.1632312/)
- [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/)
- [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/)
- [how do i keep sections from moving when i minimize window?] (https://www.tek-tips.com/threads/how-do-i-keep-sections-from-moving-when-i-minimize-window.1611893/)
- [Forwarding one internal extension to External number | Tek-Tips] (https://www.tek-tips.com/threads/forwarding-one-internal-extension-to-external-number.1574548/)
- [HTML h1 to h6 tag - W3Schools] (https://www.w3schools.com/tags/tag_hn.asp)
- [Creating a Healthier Future | H1] (https://h1.co/)
- [H1 Unlimited – Home of the World's Fastest Boats] (http://www.h1unlimited.com/)
- [

–

: The HTML Section Heading elements - MDN Web Docs] (https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/Heading_Elements)
- [H1 Inc. - Wikipedia] (https://en.wikipedia.org/wiki/H1_Inc.)
- [H-1B Specialty Occupations - USCIS] (https://www.uscis.gov/working-in-the-united-states/h-1b-specialty-occupations)
- [Amazon EC2 H1 Instances] (https://aws.amazon.com/ec2/instance-types/h1/)
- [Universal humanoid robot H1_Bipedal Robot_Humanoid ... - unitree] (https://www.unitree.com/h1)
- [Our Trapped Ion Quantum Computers | System Model H1] (https://www.quantinuum.com/products-solutions/quantinuum-systems/system-model-h1)
- [H1 - LinkedIn] (https://www.linkedin.com/company/h1co)