November Black Friday Python week
This week up to 80% off on Python courses. More info
Black friday is here! Get up to 80 % extra points for free! More info

Discussion: Issue with ASCII codes

Activities (3)
Avatar
jmillberry
Member
Avatar
jmillberry:11/11/2016 14:08

I thought I understood ASCII codes from the lesson, but I don't get why casting a string to an int gives its ASCII value...

int i = (int)c;
i += shift;
// overflow control
if (i > (int)'z')
        i -= 26;
char character = (char)i;
message += character;

I know, noob alert, but can someone please tell me why that is?

 
Reply 11/11/2016 14:08
Avatar
Replies to jmillberry
Luboš 'Satik' Běhounek:11/11/2016 15:56

When you cast char to int, you get the ascii value of the char, because all chars are in memory stored as corresponding number value.

 
Up Reply 11/11/2016 15:56
Avatar
Replies to Luboš 'Satik' Běhounek
Prince Vivek Ozovehe:5/24/2017 13:23

If u cast char in to into,u will get ASCII BC all the memory is been stored corresponding number value or digit

 
Up Reply 5/24/2017 13:23
To maintain the quality of discussion, we only allow registered members to comment. Sign in. If you're new, Sign up, it's free.

3 messages from 3 displayed.