This is some kind of obfuscation or micro-optimization:
ret << 3
isret * 8
ret << 1
isret * 2
So (ret << 3) + (ret << 1)
is actually ret * 10
. Then, on common implementation, the integer value of the character '0'
is 48
(ascii value), so:
(ret << 3) + (ret << 1) - 48
Is actually:
ret * 10 - '0'
So this code is basically a “weird” way of converting a string representing a number (returned by successive call to gc()
) to an int
.
1
solved can you explain the working of ret variable in the code below? [closed]