mIRC Home    About    Download    Register    News    Help

Print Thread
C++ bitwise operators in an identifier, like $calc #264431 28/11/18 09:48 AM
Joined: Dec 2002
Posts: 198
T
Talon Offline OP
Vogon poet
OP Offline
Vogon poet
T
Joined: Dec 2002
Posts: 198
It would be handy when needing to do multiple bitwise operations to have an identifier capable of doing these based on the standard C++ bitwise operators syntax: &, |,^ ,~, <<, >>

which is and, or, xor, not, shift-left, shift-right.

Currently there are no bitwise operations in mIRC for bit-shifting.

I've whipped up an example identifier:
Code:
bitwise { 
  var %pattern = /^(\d+)([\x26\x7C\x5E\x7E]|<<|>>)(\d+)/
  while ($regex($1,%pattern)) { tokenize 32 $regsubex($1,%pattern,$iif($len(\2) > 1,$calc(\1 $iif(\2 = >>,//,*) 2 ^ \3),$eval($+($,$gettok(and or xor not,$pos(&|^~,\2,1),32),(\1,\3)),2))) }
  return $1
}


this greatly reduces multiple bitwise tasks and makes for cleaner easier to follow conditions rather than something like $and($or($xor($not())))

The hard way, Example:
//echo -a $and($base(1 $+ $str(0,3),2,10),7)

Output:
0

VS-

The easy way, Example:
//echo -a $bitwise(1<<3&7)

Output:
0

The only issue i see is trying to support spacing between bitwise operations since | is already a special character implying a new line which would break things. as long as there is no spaces between, so you do like "x|x" there's no issue, or $+(x,|,x), etc... or maybe even replace bitwise inclusive or with another character.

Also it should be known that there's no wrap for bitshifting, since there is no way to create types like uint8 or something when bitshifting out-of scope for such a type.

It would also be nice to have compound assignment operators for variables, such as: +=, -=, *=, /=, %=, >>=, <<=, &=, ^=, |=

Examples:
%x += 3
%y *= 2

but I guess that should be another feature thread of it's own.

Re: C++ bitwise operators in an identifier, like $calc [Re: Talon] #264432 28/11/18 09:58 AM
Joined: Feb 2003
Posts: 2,641
Raccoon Offline
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2003
Posts: 2,641
I support this. Beat me to posting.

Would be better in an optimized rewrite of $calc() smile


Well. At least I won lunch.
Good philosophy, see good in bad, I like!
Re: C++ bitwise operators in an identifier, like $calc [Re: Raccoon] #264433 28/11/18 01:48 PM
Joined: Dec 2008
Posts: 1,511
westor Offline
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2008
Posts: 1,511
Great idea +1