Skip to content

Latest commit

 

History

History
24 lines (16 loc) · 1.02 KB

binary_representation.md

File metadata and controls

24 lines (16 loc) · 1.02 KB

Binary Representation

For example, the C expression (3.14+1e20)-1e20 will evaluate to 0.0 on most machines, while 3.14+(1e20- 1e20) will evaluate to 3.14. Be careful!

little endian : the least significant byte comes first—is referred to as little endian.

big endian : the most significant byte comes first—is referred to as big endian.

//No need to take a local variable. No performance improvement.
void inplace_swap(int *x, int *y) {
    *y = *x ^ *y;
    *x = *x ^ *y;
    *y = *x ^ *y;
}

Looking at the following program(my machine is 64 bit)

string str("");
cout << str.length()-1 << endl;
cout << (((unsigned long)2 << 63)-1) << endl;

What will the program output? -1? NO! In my machine, it outputs 18446744073709551615 . Because length() return a size_t data type, so there is a type conversion. 18446744073709551615 is the maximum value of unsigned long in my machine.