java - Int verification -


looking @ android support library saw can't think why it:

 /**  * simple gravity string - supports left , right debugging output.  *  * @param gravity absolute gravity value  * @return left or right appropriate, or hex string  */ static string gravitytostring(int gravity) {     if ((gravity & gravity.left) == gravity.left) {         return "left";     }     if ((gravity & gravity.right) == gravity.right) {         return "right";     }     return integer.tohexstring(gravity); } 

could explain me please.

& represents bitwise and.

example :

1100110 & 1100110 = 1100110

here pass gravity parameter. example if want know gravity left, apply mask gravity.left parameter passed. if equals constant, returns gravity left.

it applies same thing gravity.right otherwise if you're not in both cases, returns value.


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -