Go to the documentation of this file.00001
00021 #include<iostream>
00022
00023
00024
00025
00038 int& hop(int& x) {
00039 return x;
00040 }
00041
00042
00053 int& hip(int t[], int i) {
00054 return t[i];
00055 }
00056
00057
00066 void byte_print(long l) {
00067 std::cout << std::hex;
00068 unsigned char* c = (unsigned char*) &l;
00069 for(int i=0; i<sizeof(long); ++i){
00070 if(i>0)
00071 std::cout << '.';
00072 std::cout << (unsigned) *(c+i);
00073 }
00074 std::cout << std::endl;
00075 std::cout << std::dec;
00076 }
00077
00078
00085 void byte_swap(void* p, void* q) {
00086 unsigned char & c = *((unsigned char*) p);
00087 unsigned char & d = *((unsigned char*) q);
00088 c^=d; d^=c; c^=d;
00089 }
00090
00091
00096 void big_to_little(long& l) {
00097 unsigned char* p=(unsigned char*)&l;
00098 for(int i=0; i<sizeof(long)/2; ++i)
00099 byte_swap(p+i, p+(sizeof(long)-1)-i);
00100 }
00101
00102
00110 unsigned f(unsigned n, unsigned x, unsigned y) {
00111 if(n==0) return x;
00112 for(unsigned i=1u; i<n; ++i) {
00113 y=x+y;
00114 x=y-x;
00115 }
00116 return y;
00117 }
00118
00133 unsigned f(unsigned n, unsigned x=0u) {
00134 return f(n,1,x);
00135 }
00136
00137 int main() {
00138
00139 int x;
00140 hop(x)=4;
00141 std::cout << x << std::endl;
00142 int t[6];
00143 hip(t,3)=5;
00144 std::cout << t[3] << std::endl;
00145
00146 long l=246346L;
00147 byte_print(l);
00148 big_to_little(l);
00149 byte_print(l);
00150 return 0;
00151 }