What I need is a counter that counts in hex starting from 0 to C while skipping D-F all the while getting bigger untill another counter hits it's preset limit. So I could have DC4A...etc.
I want there to be a D in front of the number example D0 , D1 and after it reaches C then the output would be DD0
Thankyou
// Proof of concept.
#include <iostream>
bool is0xDEF(int val) // Simple bool function
{
int remainder = 0x0;
while (val != 0x0) // Repeat these actions until value is 0.
{
remainder = val % 0x10; // Divide by 0x10 (16)
// This gives us the last digit of the hex number.
// So 0x4DA % 0x10 returns A.
if (remainder > 0xC) returntrue; // if remainder > 0xC (12)
// If this is true, the last digit is D, E, or F
// Which we don't want. If this does not pass, we go to this step:
val = val / 0x10;
// This removes the last digit.
// So 0x4DA is now 0x4D and repeats the check above.
}
// We found no D's, E's, or F's in the loop. We can return false.
returnfalse;
}
using std::cout; using std::endl;
int main()
{
cout << std::boolalpha; // boolalpha just says true/false instead of 1/0
cout << is0xDEF(0xCD4) << '\n';
cout << is0xDEF(0xC4A) << '\n';
cout << is0xDEF(0xD33) << '\n';
cout << is0xDEF(0x00D) << '\n';
for (int i = 0x0; i < 0xFF; ++i) //Here's a loop for proof.
{
// If we see 0x## where ## is a d, e, or f, it will skip the printing of the number.
if ( is0xDEF(i) ) continue;
cout << std::hex << i << " : " << std::dec << i << '\n';
// Shows hex and decimal equivalent of i.
}
}
I am still confused about how to increment by 1 and start out with D0 and everytime it gets to D it puts another D on the total example= D0 ,D1, ...DD0,DD1 etc...
// WATCH AS I BLOW YOUR MIND
#include <iostream>
using std::cout;
using std::endl;
using std::cin;
int main()
{
for (int i = 0xD0; i < 0xDDD5; ++i) // The loop limits for testing
{
if ( (i % 0x10) > 0xC ) // Remember that % gives me the last digit.
i *= 0x10; // If the last digit is D, we multiply by 0x10 (16)
// This makes the last digit 0 again. Your mind should be blown here.
cout << std::hex << i << " : " << std::dec << i << endl; // Proof.
}
return 0;
}
One thing that confused me was that he edited his post before after my second code post, so he added the D before the C4A. So then the code I posted which removed all D's was invalid.
Then he said he wanted D in front. I don't mind running in what seems like circles but the code Duoas posted will post numbers like 0xDC then jump to 0x100. If you increase the range to 0x1000 it will run to 0xDDC then skip to 0x1000. Does that make sense?
I'm sorry that I confused everybody. I do want D I want it at the start and everytime the counter reaches D. It made perfect sense when I first thought it up, but I did not write it down and now I am confused as well.
Okay D0 to DD (not skipping D's as I first thought) all the way to 0xffffffff
You want it to count 0 1 2 ... 9 A B C 10 11 12 ... 19 1A 1B 1C 20 21 ... right?
No I don't want any numbers skipped just reencoded to the new scheme.
This is going to sound strange(as if anything I have already said isn't) but how do I make the program stop when it encounters an E in either digit -an error? I know that it will use break, but what if the digit is in the ones place instead of the tens place?
Thanks
I am trying to count from 0x00 to 0xFF and beyond but avoiding the numerals E and F(these will be for the operation to break i.e. errors)
Thanks for being so patient with me.
How you avoiding them? Do you want to skip E0 E1 E2 E3 E4... till EF and F0 F1 F2 F3 F4... until FF or do you only want to skip E as the ones digit so E0-ED is fine and so is F0-FD but EE EF FE and FF are not. Explain the counting.