Pages: 1 [2]   Go Down
Author Topic: Bin Dec Hex Oct Converter  (Read 1206 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 1
Posts: 33
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
That's an interesting question.
What if you entered 011?
Would you interpret as 3 or 9?

Sorry, I wasnt clear enough. I was using 012 as an example. I want the user to input anything as long as it is read an octal value.
Logged

Offline Offline
Newbie
*
Karma: 1
Posts: 33
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
You decided to ask the same question again, huh?

Please do not cross-post. This wastes time and resources as people attempt to answer your question on multiple threads.


Yeah, I used your sample with some modifications but the program did not work. So I thought i'd ask again to see if anyone else new. Forgot the house rules.

Apologies Nick
Logged

Des Moines, WA - USA
Offline Offline
God Member
*****
Karma: 25
Posts: 779
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Number bases are usually denoted with a prefix.

Octal values have a leading '0' character with following characters limited to '0', '1', '2', '3', '4', '5', '6' and '7'.

010 is decimal 8

Hex values have a leading two character indicator of '0x' or '0X' with the following characters limited to '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a' (or 'A'), 'b' (or 'B'), 'c' (or 'C'), 'd' (or 'D'), 'e' (or 'E'), 'f' (or 'F').

0xF is decimal 15

Binary numbers have a leading '0b' with the following characters limited to '0' and '1'.

0b1000 is decimal 8
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

He's talking about user-input not compiler input. I gave an example sketch on the previous page, not much reaction to that however.
Logged

Des Moines, WA - USA
Offline Offline
God Member
*****
Karma: 25
Posts: 779
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The same convention can be applied to user input as there is no magic way other than in indication by the user as to the input number base.

My early 6502 experience forgo's octal and has '$' proceeding hex values and '%' proceeding binary values.  Just pick something ..., anything consistent should do.
Logged

Pages: 1 [2]   Go Up
Jump to: