Advertisement
pmcgee

int to binary

Nov 27th, 2020
856
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.40 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4.       int num[10] = {0,1,2,3,4,5,6,7,8,9};
  5. const int bits    = 5;
  6. const int max     = 1<<bits;
  7.  
  8. std::string  tobits (int i) {
  9.         std::string s="";
  10.         char ch;
  11.         int b=1;
  12.         while (b<max) {
  13.                 if (i & b) ch='1'; else ch='0';
  14.                 s=ch+s;
  15.                 b<<=1;
  16.         }
  17.         return s;
  18. }
  19.  
  20. int main() {
  21.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement