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 229 views
229 views asked Aug 24, 2021 by avibootz
1 answer 337 views
1 answer 342 views
1 answer 223 views
223 views asked Sep 17, 2021 by avibootz
1 answer 226 views
226 views asked Aug 24, 2021 by avibootz
1 answer 233 views
1 answer 306 views
...