diff --git a/guide/english/miscellaneous/bitwise-operators/index.md b/guide/english/miscellaneous/bitwise-operators/index.md index e7ab87dd42..3641e11692 100644 --- a/guide/english/miscellaneous/bitwise-operators/index.md +++ b/guide/english/miscellaneous/bitwise-operators/index.md @@ -43,4 +43,22 @@ Returns x with the bits shifted to the right by y places. This is same as dividi `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. \ No newline at end of file +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 +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; +} +```