#include <stdio.h>
#if 0
void printh(int hex, int n){
for(int i=n-2;i>=1;i--){
printf("%x", (hex>>4*i)&0xf);
}
}
int main() {
int hex = 0xA123;
int b = hex;
int count = 0;
while(b!=0){
count++;
b=b>>4;
}
printf("%d\n",count);
printh(hex,count);
}
#endif
void printb(int bin, int n){
for(int i=n-2;i>=1;i--){
printf("%d", (bin>>1*i)&0b1);
}
}
int main(){
int bin = 0b010101;
int cp = bin;
int count = 0;
while(cp!=0){
count++;
cp=cp>>1;
}
printf("%d\n",count);
printb(bin, count);
}
To embed this program on your website, copy the following code and paste it into your website's HTML: