Macro to Convert Decimal Number to a Different Base

Last reviewed: November 2, 1994
Article ID: Q69777

SUMMARY

Below is a function macro to convert an integer number to any base less than 10

        =baseconv(number,base)

where "number" is the decimal number to be converted, and "base" is the number of the base to convert "number" to.

After you type the following information, select cell A1 and define the macro to be a function macro, using the Define Name command under the Formula menu:

    A1 =baseconv
    A2 =ARGUMENT("input",2)
    A3 =ARGUMENT("base",2)
    A4 =SET.NAME("quotient",input)
    A5 =SET.NAME("remainder",input)
    A6 =SET.NAME("answer","")
    A7 =WHILE(quotient<>0)
    A8 =SET.NAME("remainder",MOD(quotient,base))
    A9 =SET.NAME("quotient",TRUNC(quotient/base))
   A10 =SET.NAME("answer",remainder&answer)
   A11 =NEXT()
   A12 =RETURN(VALUE(answer))

Now the function macro is ready to use. Below is an example of how to type the function on your worksheet:

   =baseconv(100,2) would return 1100100.


KBCategory: kbother
KBSubcategory:

Additional reference words: noupd


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: November 2, 1994
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.