Hello my exercise is to convert a decimal to binary. but it has to give out as 32 bit. For example:
---
value: 5
5 = 0b00000000000000000000000000000101
---
I know how to convert it to binary but i dont no how to print it, that it looks like the example above.
Code:
This is my code:
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
void print_binary(uint32_t value){
if (value == 0)
{
printf("%" PRIu32, 0);
return;
}
else {
print_binary(value/2);
printf("%" PRIu32,(value%2));
}
}
int main (void){
uint32_t value;
scanf("%" SCNu32, &value);
printf("value: \n%u = ",value);
print_binary(value);
return EXIT_SUCCESS;
}