Advertisement
mgostih

Num to Bin with BitShifting

Oct 25th, 2016
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.33 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. char number[32] = {}; //Initialize as empty
  4.  
  5. void GetBinary(unsigned int input, char* output){
  6.     memset(output, '0', 32);
  7.     for (int i = 0; input; i++){
  8.         output[i] = (input >> 31) + '0';
  9.         input = input<<1;
  10.     }
  11. }
  12. int main(){
  13.     GetBinary(8, number);
  14.     std::cout << number << std::endl;
  15.     system("PAUSE>NUL");
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement