mIRC Home    About    Download    Register    News    Help

Topic Options
#264431 - 28/11/18 09:48 AM C++ bitwise operators in an identifier, like $calc
Talon Offline
Vogon poet

Registered: 09/12/02
Posts: 198
Loc: Ohio, USA
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:
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)



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


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: +=, -=, *=, /=, %=, >>=, <<=, &=, ^=, |=

%x += 3
%y *= 2

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

#264432 - 28/11/18 09:58 AM Re: C++ bitwise operators in an identifier, like $calc [Re: Talon]
Raccoon Offline
Hoopy frood

Registered: 18/02/03
Posts: 2594
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!

#264433 - 28/11/18 01:48 PM Re: C++ bitwise operators in an identifier, like $calc [Re: Raccoon]
westor Offline
Hoopy frood

Registered: 27/12/08
Posts: 1511
Loc: Greece
Great idea +1
Need Online mIRC help or an mIRC Scripting Freelancer? -> http://westor.ucoz.com/contact <-