Save up to 80 % on our PHP e-learning courses. Only this week!
Get up to 40 % extra points for free! More info
PHP week

Discussion: Issue with ASCII codes

Activities
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
Avatar
jamaima cyrus
Member
Avatar
jamaima cyrus:7. September 4:03

I'm a part-time programmer. Sometimes I even have trouble doing programming. Like in Loops. But I'm skeptical of seniors. After university, I am very busy with my job heftiness, so that's why I cannot do my essay. So, I, buy essay UK and get the greatest grades.

 
Up Reply
7. September 4:03
To maintain the quality of discussion, we only allow registered members to comment. Sign in. If you're new, Sign up, it's free.

4 messages from 4 displayed.