Binary to Decimal

BlitzMax Forums/BlitzMax Beginners Area/Binary to Decimal

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Does this work...
binstring:String = "011100"
val=1
For x = 0 To binstring.length
	total = total + Int(Mid(binstring , binstring.length - x , 1)) * val
	Print total + " " + val
	val = val * 2

Next


?

As a function...
SuperStrict
Print bin2dec("010011100")
Function bin2dec:Int(binval:String)
	Local Val:Int = 1
	Local total:Int
	For Local x :Int= 0 To binval.length
		total :+ Int(Mid(binval , binval.length - x , 1) ) * Val
'		debuglog Int(Mid(binval, binval.length - x , 1)) + " * " + val + " = " + total
		val = Val * 2
	Next
	Return total
End Function