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

#include <math.h> rint() Round to nearest integer double rint (double x) float rintf (float x) long double rintl (long double x) The rint() function rounds a double to the nearest integer.  It's output is still a double; For instance if double d = 5.83 x = (WORD)d; Would produce x=5 x = (WORD)rint(d); Would produce […]

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