On Wednesday 15 April 2009, Jeff Gray wrote: > > That's pretty cool. > > My only comment would be that it took me a few goes at stepping through the > code before I worked out how the blazes it worked, so perhaps less readable > than the exponent version. > > But hey - I'm no rocket scientist :-)
I'm just a ordinary Dutch cheese eating man on wooden shoes :) > > > From: ron...@tiscali.nl > > > > > > > > function bin2dec(sBin) as long > > dim r as long > > r=0 > > for i= 1 to len(sBin) > > r = r*2 + Val(Mid(sBin, i, 1)) > > next > > return r > > end You did forget the remainder. > for 10011 as sBin the sequence is as follows: > r*2=0 +1 = 1 > r*2=2 +0 = 2 > r*2=4 +0 = 4 > r*2=8 +1 = 9 > r*2=18 +1 =19 That was showing the way it works. r is your value to return +0/+1 are your bits in the string and last is the value computed each for/next loop. Best regards, Ron_1st ------------------------------------------------------------------------------ This SF.net email is sponsored by: High Quality Requirements in a Collaborative Environment. Download a free trial of Rational Requirements Composer Now! http://p.sf.net/sfu/www-ibm-com _______________________________________________ Gambas-user mailing list Gambas-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/gambas-user