Explicit Java Manipulation - What does (num>> = 1) do?

I was looking at some code that outputs a number in binary form with zeros added.

byte number = 48; int i = 256; //max number * 2 while( (i >>= 1) > 0) { System.out.print(((number & i) != 0 ? "1" : "0")); } 

and did not understand what i >>= 1 does. I know that i >> 1 is shifted to the right by 1 bit, but I didn’t understand what = doing, and as far as I know, it is impossible to search “>> =” to find out what it means,

+7
source share
1 answer

i >>= 1 is just shorhand for i = i >> 1 in the same way that i += 4 is short for i = i + 4

EDIT: In particular, these are both examples of complex assignment operators .

+13
source

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


All Articles