How to convert binary to hexadecimal in C++

1 Answer

0 votes
#include <iostream>

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;
    }
   
    std::cout << std::hex << hexadecimal;
    
    return 0;
}




/*
run:
   
1c
   
*/

 



answered Sep 17, 2021 by avibootz

Related questions

1 answer 226 views
226 views asked Aug 24, 2021 by avibootz
1 answer 233 views
1 answer 306 views
1 answer 236 views
236 views asked Sep 17, 2021 by avibootz
1 answer 229 views
229 views asked Aug 24, 2021 by avibootz
1 answer 338 views
1 answer 286 views
...