TOGGLEBIT: Difference between revisions
Jump to navigation
Jump to search
Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage
Report a broken link
No edit summary |
No edit summary |
||
(2 intermediate revisions by the same user not shown) | |||
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) | ||
{{PageAvailability}} | |||
* '''Version 1.4 and up'''. | * '''Version 1.4 and up'''. | ||
Line 36: | Line 37: | ||
0 | 0 | ||
{{OutputEnd}} | {{OutputEnd}} | ||
{{PageSeeAlso}} | {{PageSeeAlso}} | ||
* [https://qb64phoenix.com/forum/showthread.php?tid=1310 Featured in our "Keyword of the Day" series] | |||
* [[_SHL]], [[_SHR]], [[INTEGER]], [[LONG]] | * [[_SHL]], [[_SHR]], [[INTEGER]], [[LONG]] | ||
* [[_SETBIT]], [[_BYTE]], [[_INTEGER64]] | * [[_SETBIT]], [[_BYTE]], [[_INTEGER64]] | ||
* [[_RESETBIT]], [[_READBIT]] | * [[_RESETBIT]], [[_READBIT]] | ||
{{PageNavigation}} | {{PageNavigation}} |
Latest revision as of 18:20, 25 May 2024
The _TOGGLEBIT function is used to toggle a specified bit of a numerical value.
Syntax
- result = _TOGGLEBIT(numericalVariable, numericalValue)
Parameters
- numericalVariable is the variable to toggle the 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 set.
Description
- Can be used to manually manipulate individual bits of an integer value by toggling their state.
- A bit set to 1 is changed to 0 and a bit set to 0 is changed to 1.
- 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~%% = 0 '_UNSIGNED _BYTE PRINT A~%% A~%% = _TOGGLEBIT(A~%%,4) 'toggle the fourth bit of A~%% PRINT A~%% A~%% = _TOGGLEBIT(A~%%,4) 'toggle the fourth bit of A~%% PRINT A~%% |
0 16 0 |
See also
- Featured in our "Keyword of the Day" series
- _SHL, _SHR, INTEGER, LONG
- _SETBIT, _BYTE, _INTEGER64
- _RESETBIT, _READBIT