Article ID: 189323 - Last Review: July 15, 2004 - Revision: 3.4 How To Convert Between Signed and Unsigned NumbersThis article was previously published under Q189323 On This PageSUMMARY
Visual Basic for Applications only supports signed 2- and 4-byte Integers,
while other languages, such as C, support both signed and unsigned
Integers. This article provides conversion functions between signed and
unsigned 4-byte Integers and between signed and unsigned 2-byte Integers.
MORE INFORMATION
In VBA, the range of Integer values is from -32768 to +32767, and for Long
values from -2147483648 to 2147483647. When making API calls or calling a
DLL written in C, you may be requested to pass in or receive unsigned
values in the range of 0 to 65535 or 0 to 4294967296. The conversion
functions provided below convert an unsigned Integer to a Long and also
from an unsigned Long to a Double for purposes of input and display or
other calculations.
The four functions are:
UnsignedToLong LongToUnsigned UnsignedToInteger IntegerToUnsigned UnsignedToLongThe function takes a Double containing a value in the range of an unsigned Long and returns a Long that you can pass to an API that requires an unsigned Long.LongToUnsignedThe function takes an unsigned Long from an API and converts it to a Double for display or arithmetic purposes.UnsignedToIntegerThe function takes a Long containing a value in the range of an unsigned Integer and returns an Integer that you can pass to an API that requires an unsigned Integer.IntegerToUnsignedThe function takes an unsigned Integer from and API and converts it to a Long for display or arithmetic purposes.Without these functions, the input argument would have to have been specified as a signed Long, in this case -994967296, and the return value would have to be displayed as a signed value, possibly also as a negative number and non-intuitive. Step by Step Example
REFERENCES
For additional information, please see the following article in the
Microsoft Knowledge Base:
112673
(http://support.microsoft.com/kb/112673/EN-US/
)
How To Pass & Return Unsigned Integers to DLLs from VB
APPLIES TO
| Article Translations
|

Back to the top
