Computer Science Basics Flashcards
Bit manipulation: numbers representation, negative of a number, 2-compl.
The bits in the representation are indexed from right to left. To convert a bit representation bk···b2b1b0 into a number, we can use the formula
bk 2k + . . . + b2 22 + b1 21 + b0 20
For example:
1 · 25 + 1 · 23 + 1 · 21 + 1 · 20 = 43.
The bit representation of a number is either signed or unsigned. Usually a signed representation is used, which means that both negative and positive numbers can be represented. The first bit in a signed representation is the sign of the number (0 for nonnegative numbers and 1 for negative numbers), and the remaining n−1 bits contain the magnitude of the number
Two’s complement is used, which means that the opposite number of a number is calculated by first inverting all the bits in the number, and then increasing the number by one.
Memory areas allocated for processes: how many, what’s stored
- Code segment: stores the instructions to be executed and is typically read-only after the instructions have been written.
Data segment: it is the area where all data already defined in the code to initialize static and global variables are put.
Stack segment: stores the call stack and stores variables local to a function. are stored and information about functions are stored. When a function is called, a part of the stack is allocated to store information about the function (its local variables, the return address etc.) This part is called a stack frame.
Heap segment: is the are where dynamic allocations are made.
Bit manipulation, left/right shift: what it is, how it works, applications
The left bit shift x<>k removes the k last bits from the number.
A number of the form 1<
Segmentation fault: what it is, when can happen
Core Dump/Segmentation fault is a specific kind of error caused by accessing memory that “does not belong to you.”. It is an error indicating memory corruption.
This can happen:
When a piece of code tries to do read and write operation in a read only location in memory or freed block of memory, it is known as core dump.
When trying to access an element of an array out of bounds (e.g., 5th element in an array of size 4).
Bit manipulation: fundamental logic operations
- AND
The and operation x & y produces a number that has one bits in positions where both x and y have one bits. For example, 22 & 26 = 18, because 10110 & 11010 = 10010. Using the and operation, we can check if a number x is even because x & 1 = 0 if x is even, and x & 1 = 1 if x is odd. - OR
The or operation x | y produces a number that has one bits in positions where at least one of x and y have one bits. For example, 22 | 26 = 30, because 10110 | 11010 = 11110. - XOR
The xor operation x ^ y produces a number that has one bits in positions where exactly one of x and y have one bits. For example, 22 ^ 26 = 12, because 10110 ^ 11010 = 01100. - NOT
The not operation ~x produces a number where all the bits of x have been inverted. The formula ~x = −x−1 holds, for example, ~29 = − 30.
What is the Hamming distance?
The Hamming distance hamming ( a, b ) between two strings a and b of equal length is the number of positions where the strings differ. For example,
hamming (01101, 11001) = 2.
Software building processes. Difference between early and late binding.
The software building processes are:
1) Preprocessing: is where all you #directives are processed and intermediate source code for compiler is created.
2) Compilation: is where your code consisting of keywords and function calls is converted in first stage to intermediate code, then to assembly code, then to binary form. That binary form is however not ready to be executed.
3) Linking: is where all your binary output from compilation is taken together and fit into certain address space, aligned, dressed with proper meta information, etc. In this process segments are important, as all data from particular segments in object files (compilation results) are grouped together.
Binding is the process of associating variables and functions to addresses in memory. In early binding, this happens at compile time. In late binding, this happens at runtime (thanks to polymorphism, for example)
Hexadecimal notation: definition, how it works, how to convert.
Hexadecimal notation is just another base for representing numbers in, like binary. In hexadecimal, there are 16 digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, and F.
To convert, it is similar to binary notation.