Difference between revisions of "mirc/identifiers/\$bitoff"
< mirc‎ | identifiers

Commands & Identifiers
Basics
Events
Matching Tools
Data Storage
Control Structures
GUI Scripting
Sockets
Security
Other
v · d · e

\$bitoff returns N with the Bth bit set to 0.

## Synopsis

```\$bitoff(<N>,<B>)
```

## Parameters

N = Base-10 Number in the range + 2^32-1 through -2^31+1
B = Counting from the right-most bit, the bit position to set as 0

None

## Example

```//var %n 10 | echo -a \$bitoff(%n,2)
; returns 8
```

Here's how the answer was calculated:

1. Convert base-10 N to binary.
2. Count 2 from the right
3. That bit is set to 0
4. Return the possibly altered number
```//var %n 10 | echo -a \$base(%n,10,2,32) | echo -a \$str(-,24) \$+ 87654321 | echo -a \$base(\$bitoff(%n,2),10,2,32) \$base(1000,2,10)
; returns:
00000000000000000000000000001010
------------------------87654321
00000000000000000000000000001000 8
```

If N is 2^32 or greater, returns 2^32 -1
If N is less than -2^31+1, returns 2^(B-1) +1

Using \$biton and \$bitoff, you can store several variables as bits within a single variable, instead of creating a separate variable for each.
The /window switch -wN uses bit settings, with default 3 if N not used.

```var %treebarsetting \$true
var %switchbarsetting \$true
var %n
if (%switchbarsetting) var %n \$biton(%n,1)
if (%treebarsetting) var %n \$biton(%n,2)
if (%n == \$null) var %n 3
```