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 includeInt8,UInt16,Int32,UInt64, andInt128. If supplied,widthcannot be more than the size ofvalue_typein 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 SBitsandUBitsonly in a structure (Struct).
- Default value
- If you declare an element with SBitsorUBitsand 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
- SBitsand- UBitswiden to- UInt64,- UInt128,- Real32,- Real64, or- Real128without risk of overflow.
- Type characters
- SBitsand- UBitshave 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