Signed and Unsigned Integers

First, the C language uses something that is unknown to VBA: unsigned numbers. VBA uses only signed numbers. An unsigned number is a positive number; that is, it does not have a sign. A signed number can be either positive or negative because of the sign. VBA does actually support one unsigned data type: Byte. For example, Figure 14-6 shows an 8-bit byte. Having a binary 1 in the most significant bit (the eighth bit) signifies that the number contained within the byte is a negative number. A 0 in the same position indicates that the number is positive.

Most significant bit


Figure 14-6

Sometimes you'll run across numeric parameters that require an unsigned value. The general algorithm for supplying that value is to convert the value to its next highest data type, subtract the maximum value that the data type can carry, and then convert it back to the original data type.

The following table shows how to convert values from unsigned to signed, and vice versa, for the bit widths of values supported by VBA.


Convert Unsigned to Signed

Convert Signed to Unsigned


signed = CByte(unsigned - 255)

unsigned = (CInt(signed) And 255)


signed = CInt(unsigned - 65535)

unsigned = (CLng(signed) And 65535)


signed = CLng(unsigned -1.79769313486232E308)

unsigned = (CDbl(signed) And 1.79769313486232E308)

Was this article helpful?

+9 -5


  • seija jehkinen
    How do I create an unsigned number variable in vba?
    2 years ago

Post a comment