Lab 0 no grace submission, released. Due Friday 11:59pm
Bits: 0s or 1s, but represented between 0.0V and 1.1V (vultage). There exists transition period.
we can count fingers in binary instead of unary
represent int
represent scientific notation [?]
represent double [?]
Byte: 8 bits (256 different values, represent in Hexadecimal, base 16) Hexadecimal: one hex is 4 bits
Linux: long and pointer stay in the same size
Windows: long stay the same size depend on your x86 or x86-64
(in this course, assume x86-64 and the image above)
Boolean Algebra: developed by George Bool
And
Or
Not
Xor
: or but, not both, or two value not the same
Bit Vector:
Representing, Manipulating Sets using bits
Operators: &&
, ||
, !
has early termination
any anything non-zero is True
result only True
or False
, represented by 0x01
and 0x00
NULL
is a pointer, equivalent to 0x00
or False
Shifts: (good for hardware)
<<
left shift: filling with 0s
>>
right shift
undefined behavior: shift < 0 or >= word size. But shifting by 3 followed by shifting by 1 does not behave the same as shifting by 4. Example: if shifting by 4 will result undefined, and shifting by 3 will not, then shifting by 3 and 1 is allowed.
Negation with twos complement: easy
Unsigned representation: [0, 2^w - 1] Twos complement: [-2^(w-1), 2^(w-1) - 1]
Observation:
negate int_min = int_min
uint_max = 2 * int_max + 1
positive number in signed and unsigned are the same
constants are int32 in C
unsigned constants has a U
as suffix.
Casting:
casting with parenthesis
implicit casting with function input
implicit casting because being in the same expression
If there is a mixed signed and unsigned in expression, everything will be cast to unsigned (therefore using unsigned relation).
Extension: extend left bits (keep negative) to preserve value
Trunking: just cut down if you can actually represent (not losing representation). Otherwise, keep bit pattern
small positive: okay
large positive: actual value minus the highest weight
small negative: okay
very negative: positive cuz the left most after operation is likely 0
TODO: what is x86 and x86-64 represent TODO: review 15122 bits
Table of Content