prize18-3 Exercise 2: Latin-1 Against Windows-1252 =================================================== Prediction: the two tables agree everywhere except 0x80 to 0x9F (32 values). In that block Latin-1 has control characters and Windows-1252 has printable characters, except for five bytes that Windows-1252 leaves undefined (0x81, 0x8D, 0x8F, 0x90, 0x9D). So 0x9D should print "(undefined)" and the rest should differ. ex2.py: def compare(b): one = bytes([b]).decode("latin-1") try: two = bytes([b]).decode("cp1252") except UnicodeDecodeError: two = "(undefined)" return one, two for b in [0x80, 0x85, 0x92, 0x93, 0x99, 0x9D, 0xA3, 0xE9]: one, two = compare(b) print(f"0x{b:02X} latin-1 U+{ord(one):04X} cp1252 {two!r}") diff = [b for b in range(256) if compare(b)[0] != compare(b)[1]] print(len(diff), "differ, all inside", hex(min(diff)), "-", hex(max(diff))) Real output (Python 3.14): 0x80 latin-1 U+0080 cp1252 '€' 0x85 latin-1 U+0085 cp1252 '…' 0x92 latin-1 U+0092 cp1252 '’' 0x93 latin-1 U+0093 cp1252 '“' 0x99 latin-1 U+0099 cp1252 '™' 0x9D latin-1 U+009D cp1252 '(undefined)' 0xA3 latin-1 U+00A3 cp1252 '£' 0xE9 latin-1 U+00E9 cp1252 'é' 32 differ, all inside 0x80 - 0x9f Note that the five undefined bytes count as "differ" because the string "(undefined)" is not the Latin-1 control character.