Skip to content

Instantly share code, notes, and snippets.

@Hamleyburger
Created August 5, 2019 14:59
Show Gist options
  • Save Hamleyburger/bee6f81446776d936a1b701cddfe7e13 to your computer and use it in GitHub Desktop.
Save Hamleyburger/bee6f81446776d936a1b701cddfe7e13 to your computer and use it in GitHub Desktop.
Q&A whodunit cs50

Questions

What's stdint.h?

A header file that contains int types of specified widths and corresponding macros.

What's the point of using uint8_t, uint32_t, int32_t, and uint16_t in a program?

uint8_t is the most space saving way to store a positive int from 0-255(255 requires 8 bits). Must be positive because the "signed" is what enables the use of -/+ signs as the first bit. All these types of int have specific sizes, so you use them when you need to make sure a variable has aa specific amount of space allocated.

How many bytes is a BYTE, a DWORD, a LONG, and a WORD, respectively?

BYTE: 1 byte. WORD: 2. DWORD: 4 bytes. LONG: 4 bytes.

What (in ASCII, decimal, or hexadecimal) must the first two bytes of any BMP file be? Leading bytes used to identify file formats (with high probability) are generally called "magic numbers."

BM (Ascii), which refers to the file type of the bitmap file in the beginning of the bitmapfileheader.

What's the difference between bfSize and biSize?

bf: Bitmap File. bfSize: Contains the size of the whole bmp-file. Image, headers, everything. bi: Bitmap Info. biSize contains the size of the bitmapinfoheader.

What does it mean if biHeight is negative?

The bytes representing the pixels are ordered top-down, so the first pixel printed is in the upper left corner. Goes "from 0 and down". Rows are printed top down. If it were positive rows would be printed from the bottom and up. Remember that both start printing from the left!

What field in BITMAPINFOHEADER specifies the BMP's color depth (i.e., bits per pixel)?

biBitCount

Why might fopen return NULL in copy.c?

this function takes filename and mode as arguments. In copy.c the mode iss et to "r" which means "read an already existing file". If the file does not exist fopen will return NULL.

Why is the third argument to fread always 1 in our code?

The third arg in fread indicates how many elements of size(defined in 2nd arg) to be read. Our code only reads the bmp info/file headers of its own size, and there is only one of each, so only 1 needs to be read.

What value does copy.c assign to padding if bi.biWidth is 3?

int padding = (4 - (bi.biWidth * sizeof(RGBTRIPLE)) % 4) % 4; padding = (-5 % 4) % 4 padding = 3 % 4 = 3

What does fseek do?

Moves the file pointer the number of steps given in arg 2 (here "padding" number of steps if there is any padding in the current position?)

What is SEEK_CUR?

Current position of file pointer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment