CS208 Introduction to Computer Systems Wednesday, 1 October 2025 + Questions + When does the leftmost bit matter? - "sign extension" - integer types - [1 byte] char, unsigned char - [2 bytes] short, unsigned short - [4 bytes] int, unsigned int - [8 bytes] long, unsigned long - [16? bytes] long long, unsigned long long - typecasting char c = 0x41; // A or 65 int n = (int)c; // legal, and makes n's value 65 int n = c; // legal, and makes n's value 65 c 0100 0001 n 0000 0000 0000 0000 0000 0000 0100 0001 If you induce a typecast into a signed type, then the smaller type (char in this case) gets "sign-extended". That is, if the smaller thing (c) is a positive integer (leftmost bit 0), then the int fills in with 0's. If the smaller is negative (leftmost bit 1), the int fills in with 1's. char c = 0xC3; // -61 int n = (int)c; // legal, and makes n's value -61 int n = c; // legal, and makes n's value -61 c 1100 0011 n 1111 1111 1111 1111 1111 1111 1100 0011 - automatic typecasting - right shift >> int n = -61; int y = n >> 4; n 1111 1111 1111 1111 1111 1111 1100 0011 y 1111 1111 1111 1111 1111 1111 1111 1100 + What's next - overall memory layout - malloc, free, and why - buffer overflow--first glimpse - structs - . - typedef - syntactical weirdness of typedef - pointers - syntax: &, *, **, [], ->, ++, -- - looping with pointers - arrays, pointer variables, literals, etc. - string library functions + memory.c - see today's LAB https://wiki.sei.cmu.edu/confluence/display/c/INT02-C.+Understand+integer+conversion+rules