Sum of char in a int | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Sum of char in a int

Saw that code in a challenge (and I messed up). The output is "yo", and I have no idea of how it works. Someone could me explain?

5th Nov 2017, 6:10 PM
Lucas Costa
Lucas Costa - avatar
2 Answers
+ 2
I've commented out the code you provided, braking it into small steps. Take a look ask if any particular step isn't clear. UPDATE: Forgot to mention one important thing. x86 platform is little endian, so the least significant byte is stored first. So our integer 00006f79 is read backwards in the string, like 796f0000.
5th Nov 2017, 7:04 PM
Amazing! I would never figure out what's going on... Had to learn some more to understand the explanation, and now I got it. Thank you so much!
6th Nov 2017, 10:10 AM
Lucas Costa
Lucas Costa - avatar