Bit_Set

<< Click to Display Table of Contents >>

Navigation:  ThinBASIC Core Language > BuiltIn Functions > Numeric functions >

Bit_Set

 

Description

 

Set to 1 (one) a particular bit and return changed value

 

Syntax

 

nBit = BIT_Set(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

 

See also

 

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

 

PrintL

PrintL "Now changing some bits"

 

l = Bit_Reset(l, 19)

PrintL "After reset  Bit 19 is now "Bit_Get(l, 19) '---Will return 0

l = Bit_Toggle(l, 19)

PrintL "After toggle Bit 19 is now "Bit_Get(l, 19) '---Will return 1

l = Bit_Reset(l, 19)

PrintL "After reset  Bit 19 is now "Bit_Get(l, 19) '---Will return 0

l = Bit_Set(l, 19)

PrintL "After set    Bit 19 is now "Bit_Get(l, 19) '---Will return 1

 

WaitKey