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 230 views
230 views asked Aug 24, 2021 by avibootz
1 answer 338 views
1 answer 343 views
1 answer 228 views
228 views asked Sep 17, 2021 by avibootz
1 answer 227 views
227 views asked Aug 24, 2021 by avibootz
1 answer 235 views
1 answer 306 views
...