Does anyone has code on how to display an interger into its binary format? Thanks!!!![]()
This is a discussion on How to display integer to binary format? within the C++ Programming forums, part of the General Programming Boards category; 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; }
Converting Text to Binary (And Back)
Binary Converter - Various stupid string issues :p
Decimal to binary but doesn't work
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! =)