Monday, January 18, 2016

Decimal Hexidecimal Counter

If you want a list of numbers and their corresponding hexadecimal values you can do something like this. I'm sure there's a better way to it. Like some digit to hex conversion function. I need to look that up and I'll code something a little more concise for converting hex and decimal numbers. Here's a crude example of a counter that will count in decimal and hexadecimal.

#include <iostream>
#include <string>
using namespace std;

string bungee[] = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F",};

int a,b,c,d,e,f,g;
int ten=0;

int main()
{

for (a=0; a<=15; a++ ){
    for (b=0; b<=15; b++ ){
        for (c=0; c<=15; c++ ){
            for (d=0; d<=15; d++ ){
                for (e=0; e<=15; e++ ){
                    for (f=0; f<=15; f++ ){
                        for (g=0; g<=15; g++ ){

                    cout << "Hex number "<< bungee[a] << bungee[b] << bungee[c] << bungee[d] << bungee[e] << bungee[f] << bungee[g] << "    Decimal number " << ten << endl;
                        ten++;
                        }
                    }
                }
            }
        }
    }
}
    return 0;
}

No comments:

Post a Comment