Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
14
Task/Bitwise-operations/C/bitwise-operations-1.c
Normal file
14
Task/Bitwise-operations/C/bitwise-operations-1.c
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
void bitwise(int a, int b)
|
||||
{
|
||||
printf("a and b: %d\n", a & b);
|
||||
printf("a or b: %d\n", a | b);
|
||||
printf("a xor b: %d\n", a ^ b);
|
||||
printf("not a: %d\n", ~a);
|
||||
printf("a << n: %d\n", a << b); /* left shift */
|
||||
printf("a >> n: %d\n", a >> b); /* on most platforms: arithmetic right shift */
|
||||
/* convert the signed integer into unsigned, so it will perform logical shift */
|
||||
unsigned int c = a;
|
||||
printf("c >> b: %d\n", c >> b); /* logical right shift */
|
||||
/* there are no rotation operators in C */
|
||||
return 0;
|
||||
}
|
||||
5
Task/Bitwise-operations/C/bitwise-operations-2.c
Normal file
5
Task/Bitwise-operations/C/bitwise-operations-2.c
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
/* rotate x to the right by s bits */
|
||||
unsigned int rotr(unsigned int x, unsigned int s)
|
||||
{
|
||||
return (x >> s) | (x << 32 - s);
|
||||
}
|
||||
5
Task/Bitwise-operations/C/bitwise-operations-3.c
Normal file
5
Task/Bitwise-operations/C/bitwise-operations-3.c
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
rotr:
|
||||
movl 4(%esp), %eax ; arg1: x
|
||||
movl 8(%esp), %ecx ; arg2: s
|
||||
rorl %cl, %eax ; right rotate x by s
|
||||
ret
|
||||
Loading…
Add table
Add a link
Reference in a new issue