c++ - Converting binary to hex: error only on 2-7 -


i'm converting 4digit binary single digit hex using basic switch-case statement , code not run digits 0010-0111 reason , have no idea why.

here have:

void binhex() {         int binin;         cout << "enter binary(####): " << endl;         cin >> binin;          switch(binin){                 case 0000: cout << "hex: 0" << endl; break;                 case 0001: cout << "hex: 1" << endl; break;                 case 0010: cout << "hex: 2" << endl; break;                 ...         } } 

all numbers 0,1,8-15 work fine middle numbers not. ideas on causing error out/not run?

this case:

case 0010: cout<<"hex: 2\n"; break; 

will not fire binin == 10. fire binin == 8, because 0010 octal literal. drop leading 0s value gets interpreted decimal literal instead.


Comments

Popular posts from this blog

mysql - FireDac error 314 - but DLLs are in program directory -

git - How to list all releases of public repository with GitHub API V3 -

c++ - Getting C2512 "no default constructor" for `ClassA` error on the first parentheses of constructor for `ClassB`? -