Decimal and Binary Conversions
Programs created 2/20/2013
Decimal to Binary (number → string)
D2B(number)  execute from Home!
EXPORT D2B(N)
BEGIN
LOCAL str1;
D:=INT(N);
L:=INT(LN(D)/LN(2));
str1:="1";
D:=D2^L;
FOR K FROM 1 TO L DO
IF 2^(LK)≤D THEN
str1:=str1+"1";
D:=D2^(LK);
ELSE
str1:=str1+"0";
END;
END;
RETURN str1;
END;
Examples:
D2B(52) returns "110100"
D2B(131) returns "10000011"
Binary to Decimal (string → number)
Run this from Home! B2D(string of 1s and 0s). Attempting to run B2D from the program catalog will cause an error.
EXPORT B2D(str1)
BEGIN
D:=dim(str1);
N:=0;
FOR K FROM 0 TO D1 DO
N:=N+2^K*expr(mid(str1,DK,1));
END;
RETURN N;
END;
Examples:
B2D("11011") returns 27.
B2D("1010110000") returns 688.
Eddie
This blog is property of Edward Shore. 2013
A blog is that is all about mathematics and calculators, two of my passions in life.
Saturday, March 16, 2013
Decimal/Binary Conversions for the HP 39gii
Subscribe to:
Post Comments (Atom)
Update to the Big Font Math Reference
Original post: https://edspi31415.blogspot.com/2018/04/april112018sevenyears.html I added several sections to the Big Math Referenc...

Casio fx991EX Classwiz Review Casio FX991EX The next incarnation of the fx991 line of Casio calculators is the fx991 EX. ...

One of the missing features of the TI82/83/84 family is the ability to convert between bases. Here are two programs in TIBasic to help...

HP Prime: Basic CAS Commands for Polynomials and Rational Expressions Define the following variables: poly: a polynomial o...
No comments:
Post a Comment