You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The BitwiseAndAccum and BitwiseOrAccum types calculate and store the cumulative result of a series of bitwise boolean operations and store the resulting bit sequences.
656
-
The default length for both BitwiseAndAccum and BitwiseOrAccum is 64 bit.
657
-
You can specify the length of both types by appending the desired length in angle brackets``<>``.
658
-
655
+
The BitwiseAndAccum and BitwiseOrAccum types represent fixed-length bit sequences and calculate the cumulative result of a series of bitwise boolean operations and store the resulting sequences.
659
656
660
657
Fundamental to understanding and using bitwise operations is the knowledge that integers are stored in base-2 representation as a 64-bit sequence of 1s and 0s.
661
658
"Bitwise" means that each bit is treated as a separate boolean value, with 1 representing true and 0 representing false.
@@ -664,14 +661,18 @@ Computing the Bitwise `AND` of two numbers A and B means computing the bit seque
664
661
665
662
==== Declaration
666
663
667
-
A bitwise accumulator has different declaration syntax depending on its length:
664
+
The default length for a bitwise accumulator is 64 bits.
665
+
You can specify a different length by appending the desired length in angle brackets``<>`` in the declaration statement:
666
+
667
+
[,gsql]
668
+
----
669
+
@@BitwiseOrAccum<100> @visited;
670
+
----
668
671
669
-
* When a bitwise accumulator length is less than or equal to 64 bit, it's assigned using one integer.
670
-
The integer is converted to a 64-bit sequence of 1s and 0s.
672
+
* When a bitwise accumulator length is less than or equal to 64, it's stored using one 64-bit integer.
671
673
Overflow on the left is ignored.
672
-
* When a bitwise accumulator length is longer than 64 bit, it's assigned using an array of two integers.
673
-
Each integer is converted to a 64-bit sequence of 1s and 0s.
674
-
The integer in the second position will take up the first 64 bits from the right of the sequence, and the integer on the left will take up the remaining bits.
674
+
* When a bitwise accumulator length is longer than 64, it's stored using an array of multiple integers.
675
+
The rightmost (last) integer in the array is for the 64 least significant bits.
675
676
Any overflowing bits will be ignored.
676
677
677
678
For example, if you are declaring an 80-bit BitwiseAndAccum:
@@ -683,27 +684,68 @@ For example, if you are declaring an 80-bit BitwiseAndAccum:
683
684
When the two integers are joined together, the 64-bit sequence on the right (456) takes up the 64 bits from the right.
684
685
The 64-bit sequence on the left (123) takes up the remaining 16 bits and the overflow on the left is ignored.
685
686
686
-
The resulting BitwiseAndAccum prints as below:
687
-
688
-
0000000001111011 (16bits in total) 0000000...000111001000 (64bits in total)
687
+
The resulting BitwiseAndAccum is the concatenation of the two bit sequences:
689
688
689
+
0000000001111011, followed by 0000000...000111001000
690
690
691
691
692
692
==== Accumulation behavior
693
693
694
694
For BitwiseAndAccum, `+= arg` updates the accumulator's state to be the Bitwise `AND` of the current state and `arg`.
695
695
BitwiseOrAccum behaves the same, with the exception that it computes a Bitwise `OR`.
696
696
697
+
==== Bitwise Comparison and Operators
698
+
699
+
Because bitwise accumulators have values that are akin to binary integers, they support both comparison operators:
700
+
701
+
`<`, `>`, `>=`, `\<=`, `==`,`!=`
702
+
703
+
Examples: Assume AccumA and AccumB are 8-bit accumulators with the following values:
704
+
705
+
[source]
706
+
----
707
+
AccumA = 00010001; // decimal 17
708
+
AccumB = 00010000; // decimal 16
709
+
710
+
AccumA == 17 // true
711
+
AccumA > AccumB // true
712
+
AccumA < AccumB // false
713
+
----
714
+
715
+
They also support bitwise Boolean logic operators.
716
+
If an operator acts on two accumuators, the accumulators must have the same type and length.
717
+
The operation produces a new accumulator with the same type and length.
718
+
719
+
.Bitwise logic operators
720
+
[cols="1,2"]
721
+
|===
722
+
|Operator |Description
723
+
724
+
|`<accum1> & <accum2>`
725
+
|Returns a new bitwise accumulator where each bit is the Boolean `AND` of the corresponding bits in `accum1` and `accum2`.
726
+
727
+
|`<accum1> \|\| <accum2>`
728
+
|Returns a new bitwise accumulator where each bit is the Boolean `OR` of the corresponding bits in `accum1` and `accum2`.
729
+
730
+
|`<accum1> ^ <accum2>`
731
+
|Returns a new bitwise accumulator where each bit is the Boolean `XOR` (exclusive OR) of the corresponding bits in `accum1` and `accum2`.
732
+
733
+
|`~ <accum>`
734
+
|Returns a new bitwise accumulator where each bit is the Boolean `NOT` of the corresponding bit in `accum`.
735
+
|===
736
+
697
737
[CAUTION]
698
738
====
699
739
Bitwise Operations and Negative Integers
700
740
701
741
Most computer systems represent negative integers using "2's complement" format, where the uppermost bit has special significance. Operations that affect the uppermost bit are crossing the boundary between positive and negative numbers, and vice versa.
702
742
====
703
743
744
+
745
+
704
746
==== Functions
705
-
This is a list of methods of BitwiseAndAccum and BitwiseOrAccum.
706
-
If a method returns an `BitwiseAndAccum` or `BitwiseOrAccum`, it returns the same type as the instance that calls the method.
747
+
This is a list of object functions of BitwiseAndAccum and BitwiseOrAccum.
748
+
If a function returns an `BitwiseAndAccum` or `BitwiseOrAccum`, it returns the same type as the instance that calls the object function.
0 commit comments