chore: add explanation of ascii magic

main
CrimsonTome 2023-02-07 01:35:07 +00:00 committed by Rowan Clark
parent 23c1032ca7
commit 3795cb2b96
No known key found for this signature in database
GPG Key ID: F620D51904044094
1 changed files with 7 additions and 0 deletions

View File

@ -10,6 +10,13 @@ int main(){
int con = 0;
int mult[] = {4,3,2,7,6,5,4,3,2,1};
for (int i = 0; i< cprNum.length(); ++i){
// ASCII magic to convert a char of an int to its int value
// this will only work for values 0-9
// cprNum[i] holds the current character value of the integers we get from the input
// let's substitute in a value for cprNum[i] as an example
// '0' in ASCII is 48
// we'll use the number 3, its ASCII value is 51
// '3' - '0' = 51 - 48 = 3
con = cprNum[i] - '0';
sum += con * mult[i];
}