Csc373-midterm-study-guide

.pdf
School
William Rainey Harper College**We aren't endorsed by this school
Course
CSC 373
Subject
Computer Science
Date
Dec 20, 2024
Pages
5
Uploaded by HighnessSquidPerson1257
CSC 373 Study Guide: Bit-Level Operations and RepresentationsReview1.Format Characters in CUnderstand how to use format specifiers in printf:%dfor signed integers%ufor unsigned integers%xfor hexadecimal representation%pfor pointer addressesUnderstand what happen when printing unsigned numbers with %d, and signed numbers with %u2.Two's Complement RepresentationRecognize how integers are represented in two's complement.Be familiar with the properties:Most negative: 10000(for 5 bits)Negative one: 11111Most positive: 01111Largest unsigned: 11111(for 5 bits)3.Bitwise OperationsKnow how to use bitwise operators: &, |, ^, ~, <<, >>.Understand the difference between signed and unsigned integers and how implicit conversion occurs in C.4.Implicit Conversion in CBe able to identify when implicit conversions happen, particularly from signed to unsigned types and vice versa.2. Two's Complement RepresentationHow signed integers are represented in binary.The range of representable integers in a two's complement format (e.g., for 32-bit integers, from -2,147,483,648 to 2,147,483,647).The concept of TMax (maximum) and TMin (minimum) values.3. Bitwise OperationsOperations on integers using:
Background image
AND (&)OR (|)XOR (^)NOT (~)Left shift (<<)Right shift (>>)4. Implicit Conversion in CUnderstand how C handles conversions between signed and unsigned integers.Recognize the implications of such conversions on bitwise operations.
Background image
Example Questions1.What will be the output of the following code?unsigned z = 12;printf("%d\n", z);printf("0x%x\n", z);2.Given int x = -2;, what will printf("0x%x\n", x);output?3.What is the output when an unsigned integer is cast from a negative signed integer?4.Explain how the expression a ^ (-1)modifies the bits of a.5.In a two's complement representation, what is the decimal value of 0b11111111for an 8-bit signed integer?6.Write a C expression to check if any bit of xis equal to 1.7.Write a C expression that evaluates to 1 if any bit in the least significant byte of xis 1.8.How does the right shift operator behave differently for signed versus unsigned integers in C?9.Explain how the maximum integer that can be represented in a 32-bit signed integer is calculated.10.What is the result of the expression x & (-1)where xis an integer?11.Describe how to rotate an integer xleft by 8 bits using only bitwise operations.12.What will happen if you shift an integer by more than its bit length?13.How does arithmetic right shifting preserve the sign of a signed integer?14.Write a C function that returns a mask with the least significant nbits set to 1.15.What is the significance of the maximum number of operations allowed in the data lab problems, and how can you optimize your solutions to fit within those limits?
Background image
Bit Manipulation with 5-bit Integers16.What is the two's complement representation of -3in 5 bits?17.Convert the binary 01010(unsigned) to decimal.18.Interpret the binary 11100as a signed integer and as an unsigned integer.19.What is the result of the operation 5 + (-3)when both numbers are represented in 5-bit two's complement format?20.How would the unsigned interpretation of the bits change the result of -3represented in binary 11101?21.If x = -14(5-bit), what would ~xevaluate to in binary?22.What happens when you cast a signed integer to an unsigned integer in C? Provide an example with a 5-bit number.23.Explain how to identify overflow in addition using two's complement representation.24.Given x = 01111(unsigned), what is x >> 1?25.What would the result of x & ybe if x = 10101and y = 11100?
Background image
Practice ExercisesImplement the addOK function to determine if two integers can be added without overflow.Develop a function that replaces a specific byte in an integer x with a new byte b.What is the output of a C program that includes multiple printf statements with different format specifiers?Describe the process of converting a negative integer into its two's complement binary representation.* How does the representation of signed and unsigned integers differ in terms of range and bit patterns?* Write a C expression that computes the bitwise AND of two signed integers.* Explain how a right shift operator behaves with signed integers in C.
Background image