SBits and UBits Data Types

Holds integer values of a specified width in bits.

Syntax

field_name As { SBits | UBits } [ value_type ] ( width )

Parts

field_name
A name for a field in a structure.
value_type
Optional value type between brackets ([ ]). Examples include Int8, UInt16, Int32, UInt64, and Int128. If supplied, width cannot be more than the size of value_type in bits.
width
An integer literal for the number of bits.

Instructions

SBits is short for “signed bits” and UBits is short for “unsigned bits”.

Contexts
You can declare elements of SBits and UBits only in a structure (Struct).
Default value
If you declare an element with SBits or UBits and do not initialize it, its default value is zero (0).
Negation

If you use the negation operator (-) on an unsigned type, ViviFire gives a warning that this operation is usually an error.

If you subtract a larger number from a smaller number, you find the result as follows:

number Mod UBits(width).Max + 1
Automatic conversions
SBits and UBits widen to UInt64, UInt128, Real32, Real64, or Real128 without risk of overflow.
Type characters
SBits and UBits have no type characters.

Shared methods and properties

SBits(width).Max As Int32
UBits(width).Max As UInt32
Returns the maximum value.
SBits(width).Min As Int32
UBits(width).Min As UInt32
Returns the minimum value. For UBits, this is always zero (0).
SBits(width).Size As Int32
UBits(width).Size As Int32
Returns the number of available bytes.

Examples

Struct foobar
    foo As SBits[UInt8](4)
    bar As UBits[UInt8](4)
End Struct

See also