### understanding someone else code.

Thx for reading, I found this code the other day and wanted to understand it so saved it, complied it, found it seemed extreemly powerful for so small a program. Then I forgot about it, went home, slept a few days, and came back to look at it today.

For the life of me I can't figure out what it's doing.
I added all the lines that say
`// test ` and the comments.

The questions I have are largely in the comments. I understand the for loop on line 19 but the one on line 33 i have not seen before. I need help on line 24 and 29 because they are not giving values that I would expect. I'm sure it's something simple I have not learned yet.

Thx in advance

 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455`` ``````// convert single char to bin 1's and 0's // ascii chart http://www.nthelp.com/ascii.htm #include #include using namespace std; int main() { char character; int i; int m[8]; cout <<"Please enter a character: "; cin >> character; cout <<"You entered: "<
character%2 will get the least significant bit of character. Dividing by two will shift the binary representation one place to the right. Then the loop repeats, getting the new least significant bit, over and over.

Does that help?
When you mod (%) the least significant digit in a number in binary format with 2 you get the remainder which is always 0 or 1, When you divide that number by 2 you effectively lop off the least significant digit. So now you have a 7 digit binary number where in the loop you repeat the mod by 2 and divide by 2, and so on. (as Zhuge has said)
Topic archived. No new replies allowed.