4 Replies Latest reply on Jul 5, 2006 6:06 AM by a¿ex

    decimal to binary conversion script

    farhanakhan Level 1
      hi

      i m very happy to all of u on ur response

      i m really happy with this forum

      i need a script to convert the decimal number in to binary number

      83---------->1010011

      thx
        • 1. Re: decimal to binary conversion script
          Chunick Level 3
          go to www.mediamacros.com and search for the word binary. That should get you a few results. Chances are there is one that will work for you.
          • 2. Re: decimal to binary conversion script
            farhanakhan Level 1
            hi
            i will check ur website thx for reply Chunick
            • 3. Re: decimal to binary conversion script
              farhanakhan Level 1
              hi chunick
              i saw ur website but there is no converion of decimal to binary script
              can u send me link of right location of website link

              can u send me script
              i will be very thk full to u
              • 4. Re: decimal to binary conversion script
                a¿ex Level 1
                here are two handlers I picked up from James Newton. I couldn't find them anywhere on his site ( http://nonlinear.openspark.com) so I paste them directly here.
                credits go to James.



                on mMakeRuleMap(anInteger)
                -------------------------------------------
                -- INPUT: <anInteger> must be an integer
                -- OUTPUT: Returns a 32-item list of 0s and 1s corresponding to the
                -- binary representation of anInteger
                --------------------------------------------------------------------

                if anInteger < 0 then
                tBinary = mMakeRuleMap(the maxInteger + 1 + anInteger)
                tBinary[1] = 1

                else
                tBinary = []
                tBits = 32
                tBinary[32] = 0

                repeat while anInteger
                tBinary[tBits] = anInteger mod 2
                anInteger = anInteger / 2
                tBits = tBits - 1
                end repeat
                end if

                return tBinary
                end mMakeRuleMap

                on mBinaryToDecimal(aBitList)
                ----------------------------------------
                -- INPUT: <aBitList> is a list of 0s and 1s (up to 32 items)
                -- OUTPUT: a decimal number corresponding to the binary number
                -- defined by <aBitList>
                --------------------------------------------------------------------

                tBitValue = 1
                tDecimal = 0

                i = aBitList.count
                if i = 32 then
                if aBitList[1] = 1 then
                -- The number is negative
                i = 31
                tDecimal = the maxInteger + 1
                end if
                end if

                repeat while i
                if aBitList then
                tDecimal = tDecimal + tBitValue
                end if
                tBitValue = tBitValue * 2
                i = i - 1
                end repeat

                return tDecimal
                end mBinaryToDecimal