I just completed the vigenere problem set and I had this weird bug which, despite fixing it, don't understand why it was a bug. When I was implementing the caesar shift part, I added the plaintext char and the shift int value and stored them in a char called mod_c (modified char). however, for some reason this led to mod_c int value to be negative. When I changed it from type char to type int, everything worked perfectly.

Why did this happen?

char lower_caesar(char plain_char, int shift)
    char mod_c = plain_char + shift;


1 Answer 1


From the Data Types Short starting at 3:14, Doug explains that chars have values in the -128 to 127 range (ie they are "signed"). Any data that would make mod_c greater than 128, therefore, would be a negative number. Eg if plain_char is z and shift is 8, the result is a negative number.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .