SBits and UBits Data Types

Holds integer values of a specified width in bits.

Syntax

field_name As { SBits | UBits } ( width )

Parts

field_name
A name for a field in a structure.
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, then 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, the result is calculated as follows:

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

Shared methods and properties

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

Examples

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

See also