READBIT: Difference between revisions

From QB64 Phoenix Edition Wiki
Jump to navigation Jump to search
(Created page with "{{DISPLAYTITLE:_READBIT}} The _READBIT function is used to check the state of a specified bit of a integer value. {{PageSyntax}} :{{Parameter|result}} = _READBIT({{Parameter|numericalVariable}}, {{Parameter|numericalValue}}) {{Parameters}} * {{Parameter|numericalVariable}} is the variable to read the state of a bit of and can be of the following types: _BYTE, INTEGER, LONG, or _INTEGER64. * Integer values can be signed or _UNSIGNED. * {{Pa...")
 
No edit summary
 
(2 intermediate revisions by the same user not shown)
Line 7: Line 7:




{{Parameters}}
{{PageParameters}}
* {{Parameter|numericalVariable}} is the variable to read the state of a bit of and can be of the following types: [[_BYTE]], [[INTEGER]], [[LONG]], or [[_INTEGER64]].
* {{Parameter|numericalVariable}} is the variable to read the state of a bit of and can be of the following types: [[_BYTE]], [[INTEGER]], [[LONG]], or [[_INTEGER64]].
* Integer values can be signed or [[_UNSIGNED]].
* Integer values can be signed or [[_UNSIGNED]].
Line 18: Line 18:
* Bits start at 0 (so a [[_BYTE]] has bits 0 to 7, [[INTEGER]] 0 to 15, and so on)
* Bits start at 0 (so a [[_BYTE]] has bits 0 to 7, [[INTEGER]] 0 to 15, and so on)


==Availability==
 
{{PageAvailability}}
* '''Version 1.4 and up'''.
* '''Version 1.4 and up'''.


Line 54: Line 55:
* [[_SETBIT]], [[_BYTE]], [[_INTEGER64]]
* [[_SETBIT]], [[_BYTE]], [[_INTEGER64]]
* [[_RESETBIT]], [[_TOGGLEBIT]]
* [[_RESETBIT]], [[_TOGGLEBIT]]


{{PageNavigation}}
{{PageNavigation}}

Latest revision as of 01:00, 29 January 2023

The _READBIT function is used to check the state of a specified bit of a integer value.


Syntax

result = _READBIT(numericalVariable, numericalValue)


Parameters

  • numericalVariable is the variable to read the state of a bit of and can be of the following types: _BYTE, INTEGER, LONG, or _INTEGER64.
  • Integer values can be signed or _UNSIGNED.
  • numericalValue the number of the bit to be read.


Description

  • Used to check the current state of a bit in an integer value.
  • Returns -1 if the bit is set(1), otherwise returns 0 if the bit is not set(0)
  • Bits start at 0 (so a _BYTE has bits 0 to 7, INTEGER 0 to 15, and so on)


Availability

  • Version 1.4 and up.


Examples

Example 1:

A~%% = _SETBIT(A~%%,4)
PRINT "Bit 4 is currently ";
IF _READBIT(A~%%,4) = -1 THEN PRINT "ON" ELSE PRINT "OFF"
PRINT "And bit 2 is currently ";
IF _READBIT(A~%%,2) = -1 THEN PRINT "ON" ELSE PRINT "OFF"
Bit 4 is currently ON
And bit 2 is currently OFF

Example 2:

B& = 12589575
PRINT "B& ="; B&
FOR I%% = 31 TO 0 STEP -1 '32 bits for a LONG value
 Binary$ = Binary$ + LTRIM$(STR$(ABS(_READBIT(B&, I%%))))
NEXT I%%
PRINT "B& in binary is: "; Binary$
B& = 12589575
B& in binary is: 00000000110000000001101000000111


See also



Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage
Report a broken link