Macro to Convert Decimal Number to a Different BaseLast reviewed: November 2, 1994Article ID: Q69777 |
SUMMARYBelow 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
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |