Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /******************************************************************************
- Online C++ Compiler.
- Code, Compile, Run and Debug C++ program online.
- Write your code in this editor and press "Run" button to compile and execute it.
- *******************************************************************************/
- #include <iostream>
- using namespace std;
- #define LEN 10
- void getBin(int value);
- int main()
- {
- int n= 10;
- getBin(n);
- return 0;
- }
- void getBin(int value) {
- int temp = value;
- int bin[LEN]= {0};
- int r;
- int index=0;
- while(temp > 1) {
- r = temp % 2;
- temp /= 2;
- bin[index++] = r;
- }
- bin[index] = temp;
- cout << "origin: ";
- for(int i=index;i>=0;i--) {
- cout << bin[i] << " ";
- }
- cout << endl;
- //reverse
- cout << "reverse: ";
- for(int i=0;i<=index;i++) {
- cout << bin[i] << " ";
- }
- cout << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement