[Solved] can you explain the working of ret variable in the code below? [closed]


This is some kind of obfuscation or micro-optimization:

  • ret << 3 is ret * 8
  • ret << 1 is ret * 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]