Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Binary to Decimal Function

From: ptretter::charter::net at: 25-Aug-2000 22:52

Librarian comment

Or use this script to convert any base to any other base: base convert 

Here is a useful function for anyone needing to convert binary digits to decimal. Took me awhile but here it is: bnfunc: func [ "Convert Binary digits to Decimal equivalent" bn [string!] "The binary representation" /local holder count][ holder: make integer! 0 reverse bn count: length? bn for x 1 count 1 [ if (to-string (pick bn x)) = "1" [ holder: (2 ** (x - 1)) + holder ] ] return holder ] Let me know what you think. I am gonna create some refinements to enhance it a bit. Paul Tretter