Computer-scientist functions on HP Prime?



#14

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?


#15

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.


#16

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.


#17

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 ?


#18

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.

#19

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.

#20

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.

#21

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.

#22

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

#23

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.


#24

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


#25

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

#26

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


Possibly Related Threads...
Thread Author Replies Views Last Post
  Use 82240B as computer printer R. Pienne 3 298 12-09-2013, 12:19 PM
Last Post: Marcus von Cube, Germany
  Prime: Scope of Variable and functions within programs Thomas Chrapkiewicz 9 410 11-18-2013, 03:39 PM
Last Post: Thomas Chrapkiewicz
  HP Prime - CAS functions in Spreadsheet App CR Haeger 6 368 11-11-2013, 12:37 AM
Last Post: Michael de Estrada
  [41CL] New Extra Functions version Monte Dalrymple 0 148 11-08-2013, 04:32 PM
Last Post: Monte Dalrymple
  HP Prime: in need of help with defining functions Alberto Candel 14 654 10-27-2013, 10:48 AM
Last Post: Alberto Candel
  OT: Jeppesen E6B Wind-Easy Computer (Slide Rule) Eddie W. Shore 18 803 10-12-2013, 03:26 PM
Last Post: George Litauszky
  HP Prime spreadsheet functions SanS 0 332 10-04-2013, 04:23 AM
Last Post: SanS
  Stats functions on the HP34S Nicholas van Stigt 5 278 09-24-2013, 02:45 AM
Last Post: Nick_S
  Trig Functions Howard Owen 11 507 09-16-2013, 02:53 PM
Last Post: Fred Lusk
  50g piecewise functions Kurt Fankhauser 6 290 09-15-2013, 08:01 PM
Last Post: Kurt Fankhauser

Forum Jump: