21 lines
947 B
Mathematica
21 lines
947 B
Mathematica
XTBASE ;SLC/RWF - NUMBER BASE CHANGER ;4/9/92 07:31 ;
|
|
;;7.3;TOOLKIT;;Apr 25, 1995
|
|
K DIR S:'$D(DTIME) DTIME=$$DTIME^XUP($G(DUZ),$G(IOS))
|
|
BASE S DIR(0)="SB^2:2;8:8;10:10;16:16",DIR("A")="BASE",DIR("?")="Enter the number base you want converted" D ^DIR G END:$D(DIRUT) S BASE=Y
|
|
G BASE:(BASE<2)!(BASE>36)!(BASE\1'=BASE)
|
|
SET DIGIT=$E("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",1,BASE)
|
|
B2 W !! S DIR(0)="FO^1:20",DIR("A")="BASE "_BASE_" NUMBER",DIR("?")="Enter the number to convert" D ^DIR G END:$D(DIRUT),BASE:X="" S X=Y
|
|
IF BASE=10,X<0 S X=65536+X
|
|
F I=1:1:$L(X) IF DIGIT'[$E(X,I) W " Invalid digit in number" G B2
|
|
S X1=BASE D DEC W !,"DECIMAL ",Y S %D=Y
|
|
F J=1:1:3 S X1=$P("2^8^16","^",J),X=%D D CNV W !,$P("BINARY^OCTAL^HEX","^",J),?7," ",Y
|
|
G B2
|
|
DEC S Y=0 IF X1=10 S Y=X Q
|
|
F I=1:1:$L(X) S Y=Y*X1+($F("0123456789ABCDEF",$E(X,I))-2)
|
|
Q
|
|
CNV S Y=""
|
|
F I=1:1 S Y=$E("0123456789ABCDEF",X#X1+1)_Y,X=X\X1 Q:X<1
|
|
Q
|
|
END K DIR,BASE,X1,X,Y,I,%D,DIGIT
|
|
Q
|