From WikiChip
					
    Difference between revisions of "mirc/identifiers/$biton"    
                	
														 (→Example)  | 
				m  | 
				||
| Line 1: | Line 1: | ||
| − | {{mirc title|$biton Identifier}}  | + | {{mirc title|$biton Identifier}}'''$biton''' returns N with the Bth bit set to 1.  | 
| − | '''$biton''' returns N with the Bth bit set to 1.  | ||
== Synopsis ==  | == Synopsis ==  | ||
| − | <pre>$biton(<N>,<B>)  | + | <pre>$biton(<N>,<B>)</pre>  | 
| − | </pre>  | + | |
== Parameters ==  | == Parameters ==  | ||
N = Base-10 Number in the range + 2^32-1 through -2^31+1<br />  | N = Base-10 Number in the range + 2^32-1 through -2^31+1<br />  | ||
| Line 10: | Line 9: | ||
== Properties ==  | == Properties ==  | ||
| − | |||
None  | None  | ||
== Example ==  | == Example ==  | ||
| − | |||
<pre>//var %n 10 | echo -a $biton(%n,3)  | <pre>//var %n 10 | echo -a $biton(%n,3)  | ||
; returns 14  | ; returns 14  | ||
| Line 64: | Line 61: | ||
* [[List of identifiers - mIRC]]  | * [[List of identifiers - mIRC]]  | ||
{{mIRC identifier list}}  | {{mIRC identifier list}}  | ||
| + | [[Category:mIRC identifiers|biton]]  | ||
Revision as of 06:19, 21 September 2017
Commands & Identifiers
Basics
Events
Matching Tools
Data Storage
Control Structures
GUI Scripting
Sockets
Advanced Scripting
Additional Resources
Security
Other
$biton returns N with the Bth bit set to 1.
Synopsis
$biton(<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 1
Properties
None
Example
//var %n 10 | echo -a $biton(%n,3) ; returns 14
Here's how the answer was calculated:
- Convert base-10 N to binary.
 - Count 3 from the right
 - that bit is set to 1.
 - Return the possibly altered number
 
//var %n 10 | echo -a $base(%n,10,2,32) | echo -a $str(-,24) $+ 87654321 | echo -a $base($biton(%n,3),10,2,32) $base(1110,2,10) ; returns: 00000000000000000000000000001010 ------------------------87654321 00000000000000000000000000001110 14
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
; $biton can be simulated by using $or to set the appropriate bit to 1 //var %n 10 | var %b 3 | echo -a within the valid number range, %n $biton(%n,%b) is the same as $or( %n , $calc( 2^ (%b -1) ) )
Compatibility
Added: mIRC v5.61
Added on: 23 Sep 1999
Note: Unless otherwise stated, this was the date of original functionality.
Further enhancements may have been made in later versions.
See also
 mIRC identifier list