recurse
By: j00 | Date: Nov 19 2007 22:41 | Format: C++ | Expires: never | Size: 582 B | Hits: 1313
- #include <iostream>
- using namespace std;
- template < typename T >
- inline T highbit(T& t)
- {
- return t = (((T)(-1)) >> 1) + 1;
- }
- template < typename T >
- ostream& bin(T& value, ostream &o)
- {
- for ( T bit = highbit(bit); bit; bit >>= 1 )
- {
- o << ( ( value & bit ) ? '1' : '0' );
- }
- return o;
- }
- int main()
- {
- unsigned long value;
- cout << "Enter number: " << endl;
- cin>>value;
- cout << "dec: " << dec << value << endl;
- cout << "bin: ";
- bin(value, cout);
- cout << endl;
- system("pause");
- return 0;
- }
Latest pastes
55 minutes ago
10 hours ago
1 days ago
2 days ago
2 days ago