Two’s compliment / 2’s compliment

Two’s complement is the way most computers represent integers.  The highest bit indicates positive or negative: 0b0xxxxxxx = value is positive or zero 0b1xxxxxxx = value is negative Convert positive value to negative Invert the binary digits and add one to the result. E.g. 1 / 0x01 becomes 0xFE, +1 = 0xFF Convert negative value […]

Read More

Rounding values

rint() Round to nearest integer (int) does not round values correctly!!!!!Converting a value with decimal places to an int using (int) will convert ignoring the decimal places completly. If you want a value of say 5.6 to convert to and int of 6 and not 5 then use: (int)rint() The rint() function rounds a double […]

Read More

Exponent

^ is the character for Exponent (EXP on a calculator) In C you use pow() pow(base, exponent) In C you can use exponents in two places. Firstly, where numbers are so large or so small that decimal point notation is not human-readable. For instance 100,000,000,000 is best written as 1 * 10 ^11. Secondly where […]

Read More