Programming Challenge
06-15-2017, 12:31 PM
Post: #1
 toml_12953 Senior Member Posts: 1,408 Joined: Dec 2013
Programming Challenge
Write a routine to convert a number in base 2-16 to/from base 1.

Neatness counts.

Tom L
...other than that, Mrs. Lincoln, what did you think of the play?
06-19-2017, 09:27 AM
Post: #2
 cyrille de brébisson Senior Member Posts: 976 Joined: Dec 2013
RE: Programming Challenge
Hello,

Base 1? that will be hard!

the code bellow should do it for you...
One liners for both functions...

export baseTo10(number, base) // number expressed as a list of coefitiants, most significant digit first...
begin
return Σlist(makelist(number(I)*base^(size(number)-I), I, 1, size(number)));
end;

// example baseTo10({1, 0, 1, 0, 1}, 2) -> 21

export from10ToBase(number, base)
begin
return makelist(floor((number/base^I) mod base), I, 0, log(number, base));
end;

// example from10ToBase(21, 2) -> {1, 0, 1, 0, 1}

Although I work for the HP calculator group, the views and opinions I post here are my own. I do not speak for HP.
06-19-2017, 10:46 AM
Post: #3
 DrD Senior Member Posts: 1,124 Joined: Feb 2014
RE: Programming Challenge
(06-19-2017 09:27 AM)cyrille de brébisson Wrote:  Hello,

Base 1? that will be hard!

Next challenge: provide object TYPE (number and description) for the TYPE coefitiants you've described for elements of the list, I didn't see that one in the User Guide. <g>

Very nice programming Cyrille! I took liberty of saving both programs for future use, but I did change the name so they would appear next to each other (or very nearly so) in my master program catalog:

baseTO10(number,base) and it's cousin base10TO(number,base)
06-20-2017, 12:42 AM
Post: #4
 Han Senior Member Posts: 1,817 Joined: Dec 2013
RE: Programming Challenge
There are a number of conversion programs available in the software library that will do the conversions you seek, and then some.

Graph 3D | QPI | SolveSys
 « Next Oldest | Next Newest »

User(s) browsing this thread: 1 Guest(s)