Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /***************************OUTPUT***************************\
- | [kohlrak@kohlrak-server ac3]$ g++ main.cpp |
- | main.cpp: In function ‘unsigned char* bin2str(uint32_t)’: |
- | main.cpp:7:30: error: expected ‘;’ before ‘loopy’ |
- | for(int loopy = 31; loopy+1 loopy--) ret[loopy]='0'; |
- | ^~~~~ |
- | [kohlrak@kohlrak-server ac3]$ vim main.cpp |
- | [kohlrak@kohlrak-server ac3]$ g++ main.cpp |
- | [kohlrak@kohlrak-server ac3]$ ./a.out |
- | 11101101110010111010100110000111 |
- | [kohlrak@kohlrak-server ac3]$ |
- \************************************************************/
- #include <stdio.h>
- #include <cstdint>
- unsigned char* bin2str(uint32_t x){
- const int sizeofint = 32;
- static unsigned char ret[sizeofint+1];
- for(int loopy = sizeofint-1; loopy+1; loopy--) ret[loopy]='0';
- for(uint32_t key = sizeofint-1; key+1; key--) ret[sizeofint-1-key] += (x&(1<<key))>>key;
- return ret;
- }
- int main(){
- printf("%s\n", bin2str(0xEDCBA987));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment