Logical right offset by negative integers in C?

How to do a logical right shift of negative numbers in C? I am mainly looking for the equivalent of C >>> in java

i.e.

 int one = -16711936 ; //int two = -16711936 ; //int three = -1; int r, g, b; System.out.println(Integer.toBinaryString(one)); r = one << 8; r >>>= 24; g = one << 16; g >>>= 24; //this always ends up being -1 in C, instead of 255 b = one << 24; b >>>= 24; 
+6
source share
2 answers

Before moving, change the value to (unsigned int) .

+5
source

Unlike Java, C has unsigned integer types. You should always use unsigned integer types for bitwise manipulation like this. If you are not an expert in the field of C, executing it using signed types will lead you into the terrible area of ​​undefined behavior when demons fly out of your nose.

+13
source

Source: https://habr.com/ru/post/889789/


All Articles