CS208 Introduction to Computer Systems Monday, 22 January 2024 + Questions + Topics for the week - Bit operations - Byte order - Character encodings (including UTF-16LE, UTF-16BE, UTF-8) - Prep for the exam + Bit operations - "bitwise" - OR, AND, NOT, XOR - |, &, ~, ^ ... also << and >> 0010 1110 | 1010 0000 = 1010 1110 (note: a | 0 == a) 0010 1110 & 1010 1111 = 0010 1110 (note a & ~0 == a & all-ones == a) 0010 1110 ^ 1010 0000 = 1000 1110 (a ^ 0 == a) 0010 1110 ^ 0000 1111 = 0010 0001 (a ^ all-ones == ~a) ~ 0010 1110 = 1101 0001 0010 1110 >> 2 = 0000 1011 (equiv. of integer division by power of 2) 0010 1110 << 2 = 1011 1000 (mult. by power of 2; 2^2 here) - Turning individual bits on and off 0110 0101 = x & 1101 1111 = mask --> turns off the 3rd bit from the left in x build the mask: mask = ~(0x20) 0100 0101 = x | 0010 0000 = mask --> turns on the 3rd bit from the left Interpret those examples as x == an ASCII character 0110 0101 == 'e' & 1101 1111 --------- 0100 0101 == 'E' - Masking 0110 0101 & 0000 1111 + Byte order - What's the problem? - "Endianness" - "Gulliver's Travels" and "On Holy Wars & a Plea For Peace" - Bits are bits; context determines meaning Intel x86-64 architecture uses little-endian therefore, so will we + Character encodings - What's a character encoding? - UTF-16, UTF-16LE, UTF-16BE - UTF-8 - BOM