This predicate relates a character and its integer ASCII code. The ASCII code must be an integer in the range [0, 255]. If the first argument is a character then the character code of that character is determined and unified with the second argument.
If the first argument is a variable then the character_code is translated to a character and unified with the first argument.
see also: atom_base64/2 atom_codes/2 atom_compress/2 atom_concat/3 atom_encrypt/3 atom_final_md5/1 atom_integers/2 atom_length/2 atom_reset_md5/0 atom_update_md5/1 number_chars/2 number_codes/2 number_integers/2 sub_atom/5
| Example | |
| char_code('A', 66). | 'no' is the result because the character codes 66 and 65 (of 'A') do not match |
| char_code(W, 65). | W=A is the output |
| char_code('A', C). | the value 65 is unified with C |
| Exceptions | |
| Char and Code are both variables | an instantiation_error exception is thrown |
| Char is neither a variable nor a character | a type_error(character, Char) exception is thrown |
| Code is neither a variable nor an integer | a type_error(integer, Code) exception is thrown |
| Code is an integer which is not a character code | a representation_error(character_code) exception is thrown |