Go to the documentation of this file.00001
00024 #include<iostream>
00025
00026
00027
00028
00041 int& hop(int& x) {
00042 return x;
00043 }
00044
00045
00056 int& hip(int t[], int i) {
00057 return t[i];
00058 }
00059
00060
00075 void byte_print(long l) {
00076
00077 struct conf{
00078 conf(){ std::cout << std::hex;}
00079 ~conf(){ std::cout << std::dec;}
00080 } cn;
00081
00082 unsigned char* c = (unsigned char*) &l;
00083 for(int i=0; i<sizeof(long); ++i){
00084 if(i>0)
00085 std::cout << '.';
00086 std::cout << (unsigned) *(c+i);
00087 }
00088 std::cout << std::endl;
00089 }
00090
00091
00098 void byte_swap(void* p, void* q) {
00099 unsigned char & c = *((unsigned char*) p);
00100 unsigned char & d = *((unsigned char*) q);
00101 c^=d; d^=c; c^=d;
00102 }
00103
00104
00109 void big_to_little(long& l) {
00110 unsigned char* p=(unsigned char*)&l;
00111 for(int i=0; i<sizeof(long)/2; ++i)
00112 byte_swap(p+i, p+(sizeof(long)-1)-i);
00113 }
00114
00115
00123 unsigned f(unsigned n, unsigned x, unsigned y) {
00124 if(n==0) return x;
00125 for(unsigned i=1u; i<n; ++i) {
00126 y=x+y;
00127 x=y-x;
00128 }
00129 return y;
00130 }
00131
00146 unsigned f(unsigned n, unsigned x=0u) {
00147 return f(n,1,x);
00148 }
00149
00150 int main() {
00151
00152 int x;
00153 hop(x)=4;
00154 std::cout << x << std::endl;
00155 int t[6];
00156 hip(t,3)=5;
00157 std::cout << t[3] << std::endl;
00158
00159 long l=246346L;
00160 byte_print(l);
00161 big_to_little(l);
00162 byte_print(l);
00163 return 0;
00164 }