User Tools

Site Tools



Bit and Byte Modifiers

A variable’s bits and bytes can be accessed individually by using the commands shown below:

Dim A As Integer
A.LowByte = &H12      ' Store &H12 at A’s lowest byte

NOTE: These bit, nibble, and byte modifiers is not supported for the Single type, but are supported for the Integer and Long data types.

NOTE: These bit, nibble, and byte modifiers is not supported for the Ladder Logic sharing variable.

_D(10).byte0 ' No supported

Dim A As Integer
Dim B As Byte
A = _D(10)
B = A.byte0 ' Move it like this


LOWBIT Variable’s bit 0
BIT0 to 31 Variable’s bit 0 through 31
A.BIT2 = 1          ' Make bit 2 of A equal to 1.


A nibble is 4 bits. The user can access individual nibbles to make processing certain data formats easier.

LOWNIB Variable’s NIBBLE 0
NIB0 to 7 Variable’s NIBBLE 0 to 7
A.NIB3 = 7 ' Store 7 in Nibble 3 of A


To access specific bytes of a variable, the following can be used.

LOWBYTE, BYTE0 BYTE 0 of Variable
BYTE1 BYTE 1 of Variable
BYTE2 BYTE 2 of Variable
BYTE3 BYTE 3 of Variable
A.Byte1 = &HAB     'Store &HAB in byte 1 of variable A


To specify a certain Word of a variable, the following can be used: (A Word is 16 bits)

LOWWORD, WORD0 Word 0 of variable
WORD1 Word 1 of variable
A.Word1 = &HABCD     Store &HABCD in word 1 of variable A

* Tip: Need to access 5 bits of a variable?

NewVariable = Variable AND 0x1F.

This will mask the last 5 bits of the variable.

Expressing Numbers

There are three possible ways to represent numbers in Cubloc BASIC: binary, decimal and hexadecimal. The binary and hexadecimal representations are useful when interfacing to digital devices. The decimal representation is the standard human readable format.


Binary : &B10001010, &B10101,0b1001001, 0b1100
Decimal : 10, 20, 32, 1234
Hexadecimal : &HA, &H1234, &HABCD,

            0xABCD, 0x1234        <-- Similar to C

Go CUBLOC home

cubloc/modifiers_expressing_numbers/index.txt · Last modified: 2023/07/06 05:34 by COMFILE Technology