i am making a number base conversion program in c++,

suppose that user enters an base 2 number and want to convert that number in base 4. when he enter the number (which he wants to be converted), how can i detect that number is belongs to base 2 number system or not.

for example: if user enter 1001011001 , program should continue and convert that number to base 4. and if user enter 1200101 or 1001012 , program should not convert that number and output that this number is not belongs to base 2 number system. waiting for your kind reply. thanks.

kamalashraf
0
Newbie Poster

## Recommended Answers

Jump to PostWell you can take the number in as a string and make sure that there is only 1's and 0's in it.

Jump to PostIf you only need to determine whether a number

couldbe in a certain base, just check the digits. If there are any illegal digits for the base, you can exclude that base.If you need to say conclusively that something like 1001011001 is binary, it's much harder. That particular …

## All 6 Replies

NathanOliver
429
Veteran Poster
Featured Poster

kamalashraf
0
Newbie Poster

deceptikon
1,790
Code Sniper
Administrator
Featured Poster

kamalashraf
0
Newbie Poster

Moschops
683
Practically a Master Poster
Featured Poster

Banfa
597
Posting Pro
Featured Poster

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.