kohlrak

Untitled

Mar 27th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.19 KB | None | 0 0
  1. /***************************OUTPUT***************************\
  2. | [kohlrak@kohlrak-server ac3]$ g++ main.cpp                 |
  3. | main.cpp: In function ‘unsigned char* bin2str(uint32_t)’:  |
  4. | main.cpp:7:30: error: expected ‘;’ before ‘loopy’          |
  5. |   for(int loopy = 31; loopy+1 loopy--) ret[loopy]='0';     |
  6. |                               ^~~~~                        |
  7. | [kohlrak@kohlrak-server ac3]$ vim main.cpp                 |
  8. | [kohlrak@kohlrak-server ac3]$ g++ main.cpp                 |
  9. | [kohlrak@kohlrak-server ac3]$ ./a.out                      |
  10. | 11101101110010111010100110000111                           |
  11. | [kohlrak@kohlrak-server ac3]$                              |
  12. \************************************************************/
  13.  
  14. #include <stdio.h>
  15. #include <cstdint>
  16.  
  17. unsigned char* bin2str(uint32_t x){
  18.         const int sizeofint = 32;
  19.         static unsigned char ret[sizeofint+1];
  20.         for(int loopy = sizeofint-1; loopy+1; loopy--) ret[loopy]='0';
  21.         for(uint32_t key = sizeofint-1; key+1; key--) ret[sizeofint-1-key] += (x&(1<<key))>>key;
  22.         return ret;
  23. }
  24. int main(){
  25.         printf("%s\n", bin2str(0xEDCBA987));
  26.         return 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment