What would be the equivalent of :

For x = 0 To (Len(bin) - 1)
If Mid(bin, Len(bin) - x, 1) = "1" Then CDecimal = CDecimal + (2 ^ x)
Next x

in c++?? thx.