HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Binary integer operations

08-05-2008, 07:48 AM#1
d07.RiV
Implements NOT, AND, OR, XOR, SHL and SHR binary operations (bitwise not, and, or, xor, shift left, shift right)
It find it hard coming up with a real use for it except implementing standard hash methods like crc32 if you ever need them.

To use the non-vjass version, create an integer array called bintable and then either place the system code in trigger called Binary (but there is no way to make sure it can be used by other triggers) or put it in custom script and call InitTrig_Binary from any initialization function.
vJass users probably know what to do, just create a trigger, convert it to text and paste the code.

It builds a table of powers of 2 for shifts, and tables of AND/OR/XOR for all pairs of integers 0..15.
If anyone can think of a way to optimize it significantly (removing an operation or so doesn't count), it would be great.

vJass version
Expand JASS:
Non-vJass version
Expand JASS:
08-05-2008, 12:44 PM#2
DioD
omg LOL

but no, usefull for hash calculations.
08-05-2008, 01:07 PM#3
BlinkBoy
It's usefull, yet the functions are way too slow to give them a true use.
08-05-2008, 01:34 PM#4
d07.RiV
I cant think of a faster way to do it and its all because blizzards forgot to make these functions ..

But this should be enough for computing crc32 or storm-like hash.
08-05-2008, 01:36 PM#5
Vexorian
I might end up banning stuff using udg_ prefixes. Or at least make the vJass version that uses udg_ require to be scoped and the udg_ stuff to be private.

It is a huge regression to use that prefix.
08-05-2008, 01:44 PM#6
d07.RiV
It is for compatibility with non-vjass users. Just put library..endlibrary and private keyword. Ok I'll split it in 2.
08-06-2008, 02:11 PM#7
ADOLF
imho only not and shr/l useful, all another to slow and big)
08-06-2008, 06:34 PM#8
d07.RiV
You wanted to use them in 0.04 timers?
08-07-2008, 08:48 AM#9
ADOLF
Quote:
You wanted to use them in 0.04 timers
no, but in .025 - maybe)
Quote:
If anyone can think of a way to optimize it significantly
in shifts it is possible to use at once values directly, instead of to take from a array (if it is known at once) ^^
08-07-2008, 10:04 PM#10
Vexorian
All right, I am liking the implementations, could you provide benchmarks about the naive "loop through all the bits" implementations?

Approved though.
08-08-2008, 12:36 AM#11
d07.RiV
Ok 4x difference between this and AND of medium sillyness:
Expand JASS: