Data update
This commit is contained in:
parent
29a5eea0d4
commit
5c1bb7bfa9
2011 changed files with 35081 additions and 3229 deletions
32
Task/Bitwise-operations/Jq/bitwise-operations.jq
Normal file
32
Task/Bitwise-operations/Jq/bitwise-operations.jq
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
include "bitwise" {search: "."}; # adjust as required
|
||||
|
||||
def leftshift($n; $width):
|
||||
[(range(0,$n)| 0), limit($width - $n; bitwise)][:$width] | to_int;
|
||||
|
||||
# Using a width of $width bits: x << n | x >> ($width-n)
|
||||
def rotateLeft($x; $n; $width):
|
||||
$x | bitwise_or(leftshift($n; $width); rightshift($width-$n));
|
||||
|
||||
# Using a width of $width bits: x << n | x >> ($width-n)
|
||||
def rotateRight($x; $n; $width):
|
||||
$x | bitwise_or(rightshift($n); leftshift($width-$n; $width) );
|
||||
|
||||
def task($x; $y):
|
||||
def isInteger: type == "number" and . == round;
|
||||
if ($x|isInteger|not) or ($y|isInteger|not) or
|
||||
$x < 0 or $y < 0 or $x > 4294967295 or $y > 4294967295
|
||||
then "Operands must be in the range of a 32-bit unsigned integer" | error
|
||||
else
|
||||
" x = \($x)",
|
||||
" y = \($y)",
|
||||
" x & y = \(bitwise_and($x; $y))",
|
||||
" x | y = \(bitwise_or($x; $y))",
|
||||
" x ^ y = \(null | xor(x; $y))",
|
||||
"~x = \(32 | flip($x))",
|
||||
" x << y = \($x | leftshift($y))",
|
||||
" x >> y = \($x | rightshift($y))",
|
||||
" x rl y = \(rotateLeft($x; $y; 32))",
|
||||
" x rr y = \(rotateRight($x; $y; 32))"
|
||||
end;
|
||||
|
||||
task(10; 2)
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
begin
|
||||
var (a,b) := ReadInteger2;
|
||||
Println($'not {a} = {not a}');
|
||||
Println($'{a} and {b} = {a and b}');
|
||||
Println($'{a} or {b} = {a or b}');
|
||||
Println($'{a} xor {b} = {a xor b}');
|
||||
Println($'{a} shl {b} = {a shl b}');
|
||||
Println($'{a} shr {b} = {a shr b}');
|
||||
end.
|
||||
Loading…
Add table
Add a link
Reference in a new issue