Part 1
Firstrly result &= 0
is used for setting 0
to result
variable using bitwise AND
operation. Bitwise with 0 will ever return 0.
You can write it simply this way: result = 0
The better (much optimal) way of doing this is: result ^= result
. (Bitwise XOR
)
Part 2
This loop will iterate while m
is greater (or less) than 0. Because m
expression will return true
if m != 0
.
Much secure way of doing it is m > 0
.
Also you can use this expression, which is not making programm much optimal, but it will be cleaner to another programmer to understand your code: !!m
(casting m
variable to bool), which is equal to m != 0
;
Part 3
In this part ternary operator (logical_expression ? expression_1 : expression_2
) is used.
If logical_expression
is true
, then expression_1
will be executed, expression_2
will be executed otherwise.
So in your code, if this expression (arr[--m] & (0x1 << 0x1F))
returns true
then we add arr[m]
to result
variable. And do nothing in another case.
Also m
variable is decremented in ternary logical expression (arr[--m]
).
0
solved Need a simple help in C [closed]