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 133 views
133 views asked Aug 24, 2021 by avibootz
1 answer 154 views
1 answer 223 views
1 answer 149 views
149 views asked Sep 17, 2021 by avibootz
1 answer 148 views
148 views asked Aug 24, 2021 by avibootz
1 answer 234 views
1 answer 184 views
...