# question about reading inputs starting with 0

• 08-08-2004
jibbles
question about reading inputs starting with 0
i know this may seem odd but i want to read in an input starting with a 0
its a menu selection
the menu options need to be

100000
100010
000010
000011

Code:

```void readnum(int a, int b)  {   unsigned int code = 0;   printf(options);   scanf("%u", &code);   while (code != 100000 && code !=100010 && code !=000010 && code !=000011)   {     printf(options);     scanf("%u", &code);   }   if (code == 100000)     add(a, b);   if (code == 100010)     sub(a, b);   if (code == 000010)     mult(a, b);   if (code == 000011)     div(a, b);  }```
it works for the numbers starting with a 1, but not the numbers starting with a 0.
thanks!
• 08-08-2004
sean
That's because, by default, the compiler thinks you're using a decimal system, and it looks like you're using binary (or trying to). You'll need to convert all the numbers to hex and then precede each one with 0x.
• 08-08-2004
sean
To give you a little help:

000010 = 0x2
000011 = 0x3
100000 = 0x20
100010 = 0x22
• 08-08-2004
Emmanuel Delaha
Quote:

Originally Posted by jibbles
i know this may seem odd but i want to read in an input starting with a 0
its a menu selection
the menu options need to be

100000
100010
000010
000011

Beware. Constant literals beginning with 0 are considered 'octal' by the compiler.

000010 = 010 (octal) = 8 (decimal)

(BTW, there is no 'binary' literal representation in C. Use hexadecimal or octal)

octal is nice for 6 bits (2 sets of 3):

100 000 = 040
100 010 = 042
000 010 = 002
000 011 = 003

but hex is nice too and less confusing IMO.
• 08-08-2004
Salem
> if (code == 100000)
This is a decimal constant (base 10)

> if (code == 000010)
This is an octal constant (base 8)

If you really want to input and compare binary, then you'll need to do it using strings.
• 08-09-2004
jibbles
i worked it out, i could just use 11 and 10 to represent 000011 and 000010 shifty little trick :) but it did what i needed.

i'd just like to thank you all for the help you've given me over the last couple of days. i got my program working as good as needed.

THANK YOU!

i've also got alot more interested in C programming.
• 08-09-2004
quzah
It seems everyone overlooked an obvious solution:
1) Change "code" into a string.
2) Compare them to your "six bit number":
Code:

`if( strcmp( input, "100000" ) == 0 )`
Quzah.
• 08-09-2004
vsriharsha
Salem did not overlook....
Quote:

Originally Posted by quzah
It seems everyone overlooked an obvious solution:
1) Change "code" into a string.
2) Compare them to your "six bit number":
Code:

`if( strcmp( input, "100000" ) == 0 )`
Quzah.

HI Quzah,
Salem DID write that in his Response. .. (only he didnt quote an example)

-Harsha
• 08-09-2004
quzah
Quote:

Originally Posted by vsriharsha
HI Quzah,
Salem DID write that in his Response. .. (only he didnt quote an example)

-Harsha

I'm going back to bed.

Quzah.