* C Program

* fix: added code fences
This commit is contained in:
richa7327
2019-06-28 12:13:06 +05:30
committed by Randell Dawson
parent 49c2c7164a
commit f96c0ba5b9

View File

@ -44,3 +44,21 @@ Returns x with the bits shifted to the right by y places. This is same as dividi
`x >>> y` `x >>> y`
Returns x with the bits shifted to the right by y places. Unlike arithmetic shift, logical shifts do not preseve sign. For example: -2 represented in 8 bits would be 11111110 (because the most significant bit has negative weight). Shifting it right one bit using arithmetic shift would give you 11111111, or -1\. Logical right shift, however, does not care that the value could possibly represent a number; it simply moves everything to the right and fills in from the left with 0s. Shifting our -2 right one bit using logical shift would give 01111111\. This operator is not necessirly present in all languages. Returns x with the bits shifted to the right by y places. Unlike arithmetic shift, logical shifts do not preseve sign. For example: -2 represented in 8 bits would be 11111110 (because the most significant bit has negative weight). Shifting it right one bit using arithmetic shift would give you 11111111, or -1\. Logical right shift, however, does not care that the value could possibly represent a number; it simply moves everything to the right and fills in from the left with 0s. Shifting our -2 right one bit using logical shift would give 01111111\. This operator is not necessirly present in all languages.
## example in C
```c
#include<stdio.h>
int main()
{
unsigned char a = 5, b = 9;
printf("a = %d, b = %d\n", a, b);
printf("a&b = %d\n", a&b);
printf("a|b = %d\n", a|b);
printf("a^b = %d\n", a^b);
printf("~a = %d\n", a = ~a);
printf("b<<1 = %d\n", b<<1);
printf("b>>1 = %d\n", b>>1);
return 0;
}
```