Binary Data & Bitwise Operations

Cards (35)

  • What is the format of all data saved in memory and storage?
    Binary format
  • How is data accessed in memory?
    Using memory addresses (pointers)
  • What do arithmetic operations in programming handle internally?
    Binary data
  • How is binary data translated into different types of values?
    Each type has a fixed size
  • What does the highest bit in a signed type represent?
    The sign bit
  • In integer types, what do the remaining bits represent?
    The value
  • What is the purpose of two's complement?
    To represent negative integers
  • What is the size of a char type in bytes?
    1 byte
  • What is the size of a float type in bytes?
    4 bytes
  • What are the three fixed-size fields in floating-point representation?
    Sign, significand fraction, exponent
  • What does a biased exponent represent in floating-point numbers?
    It represents a range from -127 to +127
  • What is the little-endian format?
    Storing variables from the least-significant byte to the most-significant byte
  • How are elements in a 2D array saved in memory?
    Row after row
  • How can a 2D array be interpreted as a 1D array in a program?
    By using a pointer cast
  • What is the size of a structure in memory?
    Depends on the sizes of its members
  • How can data be accessed if you know its address and type?
    By casting the address to the appropriate type
  • What happens when you input values in a program and check memory using gdb?
    You can see how the values are saved in memory
  • How are the fields in a structure saved in memory?
    Members are saved contiguously in memory
  • How does a processor locate the proper elements in an array based on indexes?
    By using the type information to calculate addresses
  • What are the sizes of different data types in bytes?
    • char: 1 byte
    • short: 2 bytes
    • int: 4 bytes
    • long: 8 bytes
    • float: 4 bytes
    • double: 8 bytes
    • pointer: 8 bytes
    • size_t: 8 bytes
  • What are the steps to examine memory using gdb?
    1. Compile the program with debugging information.
    2. Start gdb with the compiled program.
    3. Set breakpoints as needed.
    4. Run the program.
    5. Use the 'x' command to examine memory.
  • How does data in memory represent different values when casted into different types?
    • The same binary data can be interpreted as different types.
    • Casting changes how the data is read and understood.
    • Example: An integer can be read as a float or char.
  • What is the significance of endianness in data representation?
    • Determines the order of bytes in memory.
    • Little-endian: least-significant byte first.
    • Big-endian: most-significant byte first.
  • How are 3D arrays saved in memory?
    • Stored in a contiguous block of memory.
    • Accessed using a single pointer by treating it as a 1D array.
    • The layout is similar to 2D arrays but with an additional dimension.
  • What is the role of the sign bit in floating-point representation?
    • Indicates if the number is positive or negative.
    • 0 for positive, 1 for negative.
  • What is the purpose of the significand fraction in floating-point representation?
    • Represents the significant digits of the number.
    • Determines the precision of the floating-point value.
  • What is the purpose of the exponent in floating-point representation?
    • Scales the significand fraction.
    • Determines the range of the floating-point number.
  • What happens if the biased exponent is 0xFF in floating-point representation?
    • The float is considered invalid.
    • It may be represented as "NaN" (Not a Number).
  • How can you explore how 2D and 3D arrays are saved in memory using gdb?
    • Compile the program with debugging information.
    • Use gdb to set breakpoints and examine memory.
    • Use the 'x' command to view the contents of the arrays.
  • What is the significance of the printf function in the provided code examples?
    • Outputs the values stored in variables.
    • Helps in debugging by showing the current state of variables.
  • How can you access the fields of a structure using their addresses?
    • Cast the address to the appropriate type.
    • Use pointer dereferencing to access the values.
  • What is the purpose of the 'scanf' function in the provided code examples?
    • Reads input from the user.
    • Stores the input values in specified variables.
  • How does the program demonstrate the use of pointers with arrays?
    • Allows treating multi-dimensional arrays as one-dimensional.
    • Facilitates accessing elements using pointer arithmetic.
  • What is the significance of the 'break' command in gdb?
    • Pauses program execution at a specified line.
    • Allows examination of memory and variable states at that point.
  • How can you modify a program to access elements of a 3D array as if it were a 1D array?
    • Use pointer casting to treat the 3D array as a 1D array.
    • Access elements using a single index based on the total number of elements.