﻿ ThinBASIC Core Language > BuiltIn Functions > Numeric functions > Bit

# Bit

Description

Return the value of a particular bit in an LONG variable

Syntax

nBit = BIT(InValue, BitNumber)

Returns

Number

Parameters

 Name Type Optional Meaning InValue Numeric No This parameter will be casted to a QUAD data type before checking bits BitNumber Numeric No The bit in question: from 31 to 0 The first bit is the least-significant bit, which is bit number zero. See example for more info

Remarks

Restrictions

Examples

Uses "Console"

Dim l As Long

'---Bits representation---------------

'---   3         2         1

'---  10987654321098765432109876543210

l = &b10000000000010000000000000000001

'---MSB = bit 31           LSB = bit 0

PrintL "Bit  0 is "Bit(l,  0) '---Will return 1 because bit  0 (LSB) is 1

PrintL "Bit 31 is "Bit(l, 31) '---Will return 1 because bit 31 (MSB) is 1

PrintL "Bit 20 is "Bit(l, 20) '---Will return 0 because bit 20 is 0

PrintL "Bit 19 is "Bit(l, 19) '---Will return 1 because bit 19 is 1

WaitKey