Thanks for your suggestions up there, but I'm just a beginner for c++ and have not gone to this extent yet. There are some code you written down I still understand yet.
So, may I know that how can I continue my code above from line 10 to if (valid)? thanks
Can you convert from base 2 to base 10 manually?
If not each column starting from the right has double the value of the previous column. The first column has a value of 1, the next 2, the next 4 then 8,16,32,64,128,256,512,1024,2048.... and so on.
To convert to base 10 from base 2 : 01110101110000110100111.
you would get (starting from the right hand end) of the binary number:
1*1+1*2+1*4+0*8+0*16+1*32+0*64+1*128...and so on.
Now you need to write some code which will perform similarly; and post again if you have difficulties.