How to convert binary to hexadecimal in C

1 Answer

0 votes
#include <stdio.h>

int main(void) {
    long int binary = 11100, hexadecimal = 0, i = 1;
    
    while (binary != 0) {
        int remainder = binary % 10;
        hexadecimal = hexadecimal + remainder * i;
        i = i * 2;
        binary = binary / 10;
    }
   
    printf("%lX", hexadecimal);
    
    return 0;
}




/*
run:
   
1C
   
*/

 



answered Sep 17, 2021 by avibootz
edited Sep 17, 2021 by avibootz

Related questions

1 answer 138 views
138 views asked Aug 24, 2021 by avibootz
1 answer 214 views
1 answer 212 views
1 answer 131 views
131 views asked Sep 17, 2021 by avibootz
1 answer 128 views
128 views asked Aug 24, 2021 by avibootz
1 answer 144 views
1 answer 208 views
...