Family Day update
This commit is contained in:
parent
aac6731f2c
commit
9ad63ea473
2442 changed files with 39761 additions and 8255 deletions
42
Task/Bitwise-operations/Harbour/bitwise-operations.harbour
Normal file
42
Task/Bitwise-operations/Harbour/bitwise-operations.harbour
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
PROCEDURE Main(...)
|
||||
local n1 := 42, n2 := 2
|
||||
local aPar := hb_AParams()
|
||||
local nRot
|
||||
|
||||
if ! Empty( aPar )
|
||||
n1 := Val( aPar[1] )
|
||||
hb_Adel( aPar, 1, .T. )
|
||||
if ! Empty( aPar )
|
||||
n2 := Val( aPar[1] )
|
||||
endif
|
||||
endif
|
||||
clear screen
|
||||
|
||||
? "Bitwise operations with two integers"
|
||||
? "n1 =", hb_ntos(n1)
|
||||
? "n2 =", hb_ntos(n2)
|
||||
? "------------------------------------"
|
||||
? "AND -->", hb_BitAnd( n1, n2 )
|
||||
? "OR -->", hb_BitOr( n1, n2 )
|
||||
? "XOR -->", hb_BitXor( n1, n2 )
|
||||
? "NOT -->", hb_BitNot( n1 )
|
||||
? "LSHIFT -->", hb_bitShift( n1, n2 )
|
||||
? "RSHIFT -->", hb_bitShift( n1, -n2 )
|
||||
? "RarSHIFT -->", hb_bitShift( n1, -n2 )
|
||||
|
||||
/* left/right rotation is not implemented, but we can use inline C-code to do it */
|
||||
/* rotate n1 to the left by n2 bits */
|
||||
nRot := hb_Inline( n1, n2 ) {
|
||||
HB_UINT x = hb_parni( 1 ), s = hb_parni( 2 );
|
||||
hb_retni( (x << s) | (x >> (-s & 31)) );
|
||||
} // (x << s) | (x >> (32 - s));
|
||||
? "Rotate left -->", nRot
|
||||
|
||||
/* rotate n1 to the right by n2 bits */
|
||||
nRot := HB_INLINE( n1, n2 ){
|
||||
HB_UINT x = hb_parni( 1 ), s = hb_parni( 2 );
|
||||
hb_retni( (x >> s) | (x << (32 - s)) );
|
||||
}
|
||||
? "Rotate right -->", nRot
|
||||
|
||||
return
|
||||
18
Task/Bitwise-operations/Pike/bitwise-operations.pike
Normal file
18
Task/Bitwise-operations/Pike/bitwise-operations.pike
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
void bitwise(int a, int b)
|
||||
{
|
||||
write("a and b: %d\n", a & b);
|
||||
write("a or b: %d\n", a | b);
|
||||
write("a xor b: %d\n", a ^ b);
|
||||
write("not a: %d\n", ~a);
|
||||
write("a << b: 0x%x\n", a << b);
|
||||
write("a >> b: %d\n", a >> b);
|
||||
// ints in Pike do not overflow, if a particular size of the int
|
||||
// is desired then cap it with an AND operation
|
||||
write("a << b & 0xffffffff (32bit cap): 0x%x\n",
|
||||
a << b & 0xffffffff);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
bitwise(255, 30);
|
||||
}
|
||||
17
Task/Bitwise-operations/Red/bitwise-operations.red
Normal file
17
Task/Bitwise-operations/Red/bitwise-operations.red
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
Red [Source: https://github.com/vazub/rosetta-red]
|
||||
|
||||
a: 10
|
||||
b: 2
|
||||
|
||||
print [
|
||||
pad "a =" 10 a newline
|
||||
pad "b =" 10 b newline
|
||||
pad "a AND b:" 10 a and b newline
|
||||
pad "a OR b:" 10 a or b newline
|
||||
pad "a XOR b:" 10 a xor b newline
|
||||
pad "NOT a:" 10 complement a newline
|
||||
pad "a >>> b:" 10 a >>> b newline
|
||||
pad "a >> b:" 10 a >> b newline
|
||||
pad "a << b:" 10 a << b newline
|
||||
; there are no circular shift operators in Red
|
||||
]
|
||||
Loading…
Add table
Add a link
Reference in a new issue