The Museum of HP Calculators

HP Forum Archive 21

[ Return to Index | Top of Index ]

Computer-scientist functions on HP Prime?
Message #1 Posted by Michael O. Tjebben on 21 Aug 2013, 7:13 a.m.

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?
Message #2 Posted by Gilles Carpentier on 21 Aug 2013, 9:32 a.m.,
in response to message #1 by Michael O. Tjebben

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?
Message #3 Posted by Patrice on 21 Aug 2013, 3:51 p.m.,
in response to message #2 by Gilles Carpentier

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?
Message #4 Posted by Gilles Carpentier on 21 Aug 2013, 4:40 p.m.,
in response to message #3 by Patrice

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?
Message #5 Posted by Tim Wessman on 21 Aug 2013, 4:47 p.m.,
in response to message #4 by Gilles Carpentier

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?
Message #6 Posted by Patrice on 21 Aug 2013, 5:14 p.m.,
in response to message #4 by Gilles Carpentier

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?
Message #7 Posted by Joe Horn on 21 Aug 2013, 5:58 p.m.,
in response to message #3 by Patrice

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?
Message #8 Posted by Patrice on 21 Aug 2013, 7:19 p.m.,
in response to message #7 by Joe Horn

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?
Message #9 Posted by Paul Dale on 21 Aug 2013, 8:08 p.m.,
in response to message #3 by Patrice

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?
Message #10 Posted by Tim Wessman on 21 Aug 2013, 1:31 p.m.,
in response to message #1 by Michael O. Tjebben

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?
Message #11 Posted by Patrice on 21 Aug 2013, 3:39 p.m.,
in response to message #10 by Tim Wessman

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?
Message #12 Posted by Michael O. Tjebben on 22 Aug 2013, 6:20 p.m.,
in response to message #11 by Patrice

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?
Message #13 Posted by plivesey on 22 Aug 2013, 6:59 p.m.,
in response to message #10 by Tim Wessman

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


[ Return to Index | Top of Index ]

Go back to the main exhibit hall