HP Forums
Computer-scientist functions on HP Prime? - Printable Version

+- HP Forums (https://archived.hpcalc.org/museumforum)
+-- Forum: HP Museum Forums (https://archived.hpcalc.org/museumforum/forum-1.html)
+--- Forum: Old HP Forum Archives (https://archived.hpcalc.org/museumforum/forum-2.html)
+--- Thread: Computer-scientist functions on HP Prime? (/thread-248543.html)



Computer-scientist functions on HP Prime? - Michael O. Tjebben - 08-21-2013

I apologize in advance if this topic has already been discussed, but I did not find anything in an hp forum search nor google.

Does the HP Prime support computer-scientist logic functions similar to what the HP16C does?

Base conversions, logic manipulations, etc?




Re: Computer-scientist functions on HP Prime? - Gilles Carpentier - 08-21-2013

Hello

I dont' know exactly what the 16C can do but the Prime manage binary, octal, decimal and hexa integer up to 64 bits, arithmetics, conversion... You can use BITAND BITNOT BITOR BITXOR, BITSL (bitwise shift left) etc.

To enter such numbers, on syntax is

#1011b // to enter a bin

#4357o // to enter octal

etc.


Edited: 21 Aug 2013, 9:33 a.m.


Re: Computer-scientist functions on HP Prime? - Tim Wessman - 08-21-2013

It supports 64 bits signed/unsigned integers. Syntax is basically #<digits>:<-><1-64><h/d/o/b> with everything after the digits being optional. You can set your default base, bitsize and signed state.

So #FFFF:-45h would be a 45 bit signed hexadecimal.

Also has this little utility for easy editing/viewing/shifting.

TW


Edited: 21 Aug 2013, 1:36 p.m.


Re: Computer-scientist functions on HP Prime? - Patrice - 08-21-2013

Just a detail.
The size goes from -63 to 64 where:
-63 is signed 64 bits (63 bits + 1 for sign)
-15 is signed 16 bits (15 bits + 1 for sign)
64 is UNsigned 64 bits


Re: Computer-scientist functions on HP Prime? - Patrice - 08-21-2013

As said the basic functions of the 16C are here but there is still a lot of them missing.

But you can create the ones you need by yourself:

EXPORT BITSET(Word, BitNum)
BEGIN
LOCAL Tmp;
Tmp:= BITSL(SETBITS(#1,GETBITS(Word)), BitNum);
RETURN BITOR(Word, Tmp);
END;

EXPORT BITCLEAR(Word, BitNum)
BEGIN
LOCAL Tmp;
Tmp:= BITSL(SETBITS(#1,GETBITS(Word)), BitNum);
RETURN BITAND(Word, BITNOT(Tmp));
END;

EXPORT BITTEST(Word, BitNum)
BEGIN
LOCAL Tmp;
Tmp:= BITSL(SETBITS(#1,GETBITS(Word)), BitNum);
RETURN (BITAND(Word, Tmp) <> #0);
END;

EXPORT BIT#(Word)
BEGIN
LOCAL Tmp, Cnt;
Cnt:= 0;
WHILE Word <> #0 DO
IF BITAND(Word, #1) <> #0 THEN Cnt:= Cnt+1; END;
Word:= BITSR(Word,1);
END;
RETURN Cnt;
END;




Edited: 21 Aug 2013, 3:52 p.m.


Re: Computer-scientist functions on HP Prime? - Gilles Carpentier - 08-21-2013

Fine ! ;)

By the way how do you convert from a base to another ?

I do an addition with the first number equal to #0base

ex:

#0b+#FFh to convert FFh in base2. Is there an integrated command ?


Re: Computer-scientist functions on HP Prime? - Tim Wessman - 08-21-2013

SETBASE/GETBASE
SETBITS/GETBITS

Remember, unlike the 48 series, numerical integers carry along information about signing, size, and base as part of the number. Similar to how numbers can be flagged as HMS. Thus there is no longer HMS+ HMS- and similar. They just work...

TW

Edited: 21 Aug 2013, 4:56 p.m.


Re: Computer-scientist functions on HP Prime? - Patrice - 08-21-2013

Properly speaking, the base conversion is mainly for display purpose.
GETBASE return the base of a value
SETBASE sets the base of the value
for size, it is GETBITS/SETBITS

Look at the little functions above, GETBITS/SETBITS are to ensure that the calculus is properly sized with the value used.


Re: Computer-scientist functions on HP Prime? - Joe Horn - 08-21-2013

Quote:
EXPORT BIT#(Word)
BEGIN
LOCAL Tmp, Cnt;
Cnt:= 0;
WHILE Word <> #0 DO
IF BITAND(Word, #1) <> #0 THEN Cnt:= Cnt+1; END;
Word:= BITSR(Word,1);
END;
RETURN Cnt;
END;

Another way to count the number of 1's in 'x' is
      hamdist(x,0) 
because the hamming distance between zero and a binary number is the number of 1's in it.


Re: Computer-scientist functions on HP Prime? - Patrice - 08-21-2013

TY I learned something today :)

looks like I should pay more attention to CAS functions.

One can also consider the function as misplaced as it would naturally fit in chapter 28 Basic Integer arithmetic.


PS looks like odd() is also a candidate to chapter 28.


Edited: 21 Aug 2013, 7:33 p.m.


Re: Computer-scientist functions on HP Prime? - Paul Dale - 08-21-2013

I looks like one's complement from the 16C and the 34S aren't there and the extra sign mode of the 34S (sign and magnitude).

Does anyone really want these extra two sign modes?
What about the carry and overflow flags?


- Pauli


Re: Computer-scientist functions on HP Prime? - Michael O. Tjebben - 08-22-2013

Thank you to everyone that responded!

It appears that the Prime will do what I am interested in doing, but not in a simple, intuitive way like the hp16c can - there is a learning curve and a small bit of study to do for the Prime that was not necessary for the hp16c.

In other words, with the hp16c, one can do all of the computer scientist functions without reading a single page of the manual.

Of course the HP16C is DEDICATED to such purposes, hence, it is difficult to fault a powerful multi-purpose unit like the Prime, which I will likely purchase simply for the interest in having such a powerful machine, especially as it can interface to data-collection and other devices.

I miss some of the fun that I had using and collecting the great set of peripherals and add-ons for the HP-41 collection.

-Mike


Re: Computer-scientist functions on HP Prime? - plivesey - 08-22-2013

This is undoubtedly me being stupid but I can't seem to get the 'Edit Integer' dialog to appear in RPN mode. In Textbook and Algebraic mode I don't have a problem. Any ideas as to what I'm doing wrong or is this confirmed behaviour?

Thanks,

Paul