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
Post a Comment