Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Binary (base 2) - Decimal Conversion
Message
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00114476
Message ID:
00114562
Views:
22
>here you have one:
>
>function bintodec
>
>lparameters cadena
>m.cadena = allt(m.cadena)
>local m.decimal
>if cadena = "0"
> return 0
>endif
>m.decimal = 0
>m.posicion = -1
>do while len(m.cadena) > 0
> m.lon = len(m.cadena)
> m.posicion = m.posicion + 1
> m.cuantas = iif(right(m.cadena, 1) = "1", 1, 0)
> m.potencia = 2^m.posicion
> m.decimal = m.decimal + m.potencia * m.cuantas
> m.cadena = left(m.cadena, m.lon - 1)
>enddo
>return round(m.decimal, 0)
>
>**************************
>function dectobin
>
>lparameters nDecimal
>local cBinString
>if nDecimal = 0
> return "0"
>endif
>cBinString = ""
>do while nDecimal > 0
> cBinString = ;
> iif(bittest(nDecimal,0),"1","0") ;
> + cBinString && Constitute righmost digit
> nDecimal = bitrshift(nDecimal,1) && Drop rightmost digit
>enddo
>return cBinString
>

Thanks everyone, for the help. As I was hoping, I didn't need to reinvent the wheel :)
The Anonymous Bureaucrat,
and frankly, quite content not to be
a member of either major US political party.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform