Does anyone has code on how to display an interger into its binary format? Thanks!!!
Does anyone has code on how to display an interger into its binary format? Thanks!!!
Code:#include <iostream> #include <stack> #include <cstddef> using std::cin; using std::cout; using std::stack; int main() { short x = -4; size_t i = sizeof(short) * 8; // short 的位数 short a = 1; stack<short> bin; for ( size_t j = 0; j != i; ++j ) { bin.push( x & a ); x >>= 1; } while ( !bin.empty() ) { cout << bin.top() ; bin.pop(); } cout << "\nPress ENTER to quit..."; cin.get(); return 0; }
http://cboard.cprogramming.com/showt...ghlight=binary
http://cboard.cprogramming.com/showt...ghlight=binary
http://cboard.cprogramming.com/showt...ghlight=binary
etc. etc. etc. etc. It gets discussed pretty frequently. Why would one ever want to do such an insane thing as this?
Antigloss, your code is really useful! Thanks for your help! =)