Showing posts with label HP 16C. Show all posts
Showing posts with label HP 16C. Show all posts

Sunday, April 21, 2024

Casio fx-CG50 and Swiss Micros DM32: HP 16C’s Bit Summation

 Casio fx-CG50 and Swiss Micros DM32: HP 16C’s Bit Summation



The HP 16C’s #B Function


The #B function is the HP 16C’s number of bits function and sums the bits that are “turned on”. To find #B, if needed, convert the number to its binary form (base 2). #B are the number of ones. Here, I am assuming the binary integers are unsigned.


For example: Calculate #B(49). Assuming 49 is in decimal base.


49_10 = 110001_2


Then #B(49) = 3



Casio fx-CG 50 Program: BITS


I thought the fx-CG 50 had functions to convert integers and logical functions, but I did not have find them. If anyone knows whether the fx-CG 50 has base conversions, please let me know. I know that earlier Casio graphing calculators had base conversions.


The binary integer form is stored in B, as long as the decimal integer is less than 2048. (2^11).


Size: 168 bytes


“DEC→BIN”

“D”? → N

N → M

0 → C

0 → B

Int (log N ÷ log 2) → L

For L → J To 0 Step -1

If M ≥ 2^J

Then

C + 1 → C

M – 2^J → M

B × 10 + 1 → B

Else

B × 10 → B

IfEnd

Next

ClrText

If N < 2049

Then

“BIN=”

B ◢

IfEnd

“#B=”

C


The hashtag character (#) is called from the CHAR menu.



Swiss Micros DM32 Program: BITS


Two labels are used:

LBL B: 68 bytes

LBL T: 92 bytes


The main program is LBL B. This should fit on the classic HP 32S/32SII calculators.


B01 LBL B

B02 CF 0

B03 SF 10

B04 “DEC NUMB”

B05 PSE

B06 INPUT N

B07 STO M

B08 Clx

B09 STO C

B10 RCL N

B11 LOG

B12 2

B13 LOG

B14 ÷

B15 IP

B16 1

B17 +

B18 STO L


T01 LBL T

T02 RCL M

T03 2

T04 RCL L

T05 1

T06 -

T07 y^x

T08 -

T09 x≥0?

T10 SF 0

T11 FS? 0

T12 LASTx

T13 FS? 0

T14 STO- M

T15 FS? 0

T16 1

T17 FS? 0

T18 STO+ C

T19 CF 0

T20 DSE L

T21 GTO T

T22 RCL N

T23 BIN

T24 STOP

T25 “BITS=”

T26 PSE

T27 CF 10

T28 DEC

T29 VIEW C

T30 GTO B


Examples


Decimal: 35, Binary: 100011, #B(35) = 3

Decimal: 36, Binary: 100100, #B(36) = 2

Decimal: 37, Binary: 100101, #B(37) = 3


Decimal: 50, Binary: 110010, #B(50) = 3

Decimal: 51, Binary: 110011, #B(51) = 4

Decimal: 52, Binary: 110100, #B(52) = 3



Sources


Hewlett-Packard. HP-16C Computer Scientists Owner’s Handbook. Hewlett-Packard Company. 1982. pg. 52



Eddie


All original content copyright, © 2011-2024. Edward Shore. Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited. This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author.

Monday, August 28, 2023

HP 15C Collector's Edition: Some Thoughts and Hidden Modes

HP 15C Collector's Edition:   Some Thoughts and Hidden Modes



On May 2, 2023, Moravia announced the return on the HP 15C programming scientific calculator.  An initial limited run  calculators were available that were delivered in July. Thankfully, another set of calculators will be available for order and delivery starting the end of September 2023.









Hopefully this will be true in future production runs, but in the initial run, the HP 15C came in a box, a Thank You card,  with a leather case and a printed manual.    I love the larger font and the clarity of the text of the Owner's Handbook.   The handbook is an extension of the original HP 15C Manual along with an introduction from Wlodek Mier-Jedrzejowicz and Gene Wright.  


You can download both the Manual and new edition of the Advanced Functions Handbook from the HP Calculator Literature website:


Manual:  https://literature.hpcalc.org/items/2258

Advanced Functions Handbook:  https://literature.hpcalc.org/items/2259


The compliment to Manual, the Advanced Functions Handbook goes into detail on several of the HP 15C's advanced features:  


Solving Equations:   The best ways for using the SOLVE command, and how the SOLVE feature finds roots of equations.  This section also includes a section of finding the derivative (approximate slope) of a function and a financial time-value-of-money program.


Integration:  The accuracy of the integral function and handling more difficult integral problems.  In general, the accuracy and the time of integration is tied to the fixed decimal settings.


Complex Numbers:  The internal workings of the complex mode (Flag 8), including solving equations and integrations.


Matrices:  LU Decomposition, constructing identity matrices, and least-squares calculations.


Programming:  No More Pause Bug


The PSE bug has been fixed!  We can use the pause command to heart's content and the display won't flash off.  


Back of the Calculator





The back of the HP 15C has a plate that has the following information:  statistics registers, some conversions, a table of error, test, and matrix codes, how the ISG (increment skip if greater than) and DSE (decrement skip if equal) commands work, and the stack effects on several two-result commands.


The Keyboard


The battery compartment, which contains the two CR2032 batteries needed to power the HP 15C is held by a small screw.  Thankfully, no special screwdriver is required, a small household or computer screwdriver should do the trick.


The keyboard, for me, is responsive.  The keys give a nice, quiet click when they are pressed.  I'm comfortable holding the calculator and letting my thumbs type on the keyboard efficiently.




Hidden Modes


Already, the HP 15C Collector's Edition has additional memory over the previous editions:


*  A maximum of 99 memory registers, 78 uncommitted registers at default setting

*  A maximum of 672 steps


We have some Easter Eggs on the HP 15C Collector's Edition.   There are two hidden modes on the HP 15C:


HP 15.2 Mode:  This mode ups the maximum of memory registers to 195, with 174 uncommitted registers at default setting.    Pressing [ g ] ( MEM ) at the beginning will show "19174 00-0", as there really isn't enough room to display the total amount of uncommitted registers.  I have my calculator in 15.2 mode and so far, this calculator works as well as the default HP 15 mode.  Switching back to 15 mode will preserve as much memory as allowed, excessive memory will be lost.  


HP 16 Mode:  This modes accesses a possible-beta version of the HP 16C calculator.   The HP 16C calculator was a popular computer programmer's calculator which emphasizes on bit manipulation, base conversions, and Boolean logic.   I worked a little bit on this mode, and there was a few problems when working in decimal integer mode.     More information on the HP 16C calculator here:  https://www.hpmuseum.org/hp16.htm


How do we switch the hidden modes on the Collector's Edition?


1.  With the calculator off: hold the [ g ], [ ENTER ], and [ ON ] keys.   This gets the calculator into test mode.

2.  Press [ 4 ].  Option 4 will not appear on the screen.

3.  Set your mode:

   * [ e^x ] for the original HP 15C Collector's Edition mode

   * [ 1/x ] for the expanded 15.2 mode  (not manufacturer supported)

   * [ 7 ] for the HP 16C mode (not manufacturer supported)


Caution:  The 15.2 and 16 modes are not manufactured supported.  Enter at your own risk.  For me, I have used the 15.2 mode and the calculator works fine.  The original mode still has plenty of memory.  


Discussion on the hidden modes starts about page 17 of this thread:

https://www.hpmuseum.org/forum/thread-19886-page-17.html



Final Thoughts


Welcome back, HP 15C!  Knock on wood the HP 15C once again becomes mainstream like it's long time financial cousin the HP 12C.

Need help with RPN (Reverse Polish Notation)?  Check out the RPN Programming tutorial series (which was done for the previous HP 15C Limited Edition) which starts here:  http://edspi31415.blogspot.com/2011/11/hp-15c-programming-tutorial-part-1.html

(Just keep in mind the pause bug that was present in the Limited Edition has been fixed in the Collector's Edition.)


Eddie 


All original content copyright, © 2011-2023.  Edward Shore.   Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited.  This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author. 


Sunday, April 18, 2021

Swiss Micros DM16L: Advanced Boolean and Factorial (up to 20)

Swiss Micros DM16L:   Advanced Boolean and Factorial (up to 20)


Introduction


The program listing, for the Swiss Micros DM16L and Hewlett Packard HP 16C,  will assign the following functions to the labels:


A:  NAND:   nand(x, y) = not(x and y)

B:  NOR:   nor(x, y) =  not(x or y)

C:  XNOR:  xnor(x, y) = (not x and not y) or (x and y)

D:  Implication:  y → x = (not y) or x

E:  Factorial:  x!  (x is a positive integer up to 20, 64 word size


NAND, NOR, NXOR, and Implication are advanced Boolean functions.  You can check out program code for the HP Prime here:


http://edspi31415.blogspot.com/2020/03/hp-prime-advanced-boolean-functions.html


Program - DM16L/HP 16C


// NAND

001 43,22,A LBL A

002 42,20   AND

003 42,30   NOT

004 43,21   RTN


// NOR

005 43,22,b LBL B

006 42,40   OR

007 42,30  NOT

008 43,21  RTN


// XNOR

009 43,22,C LBL C

010 44,1    STO 1

011 42,30  NOT

012 34      x<>y

013 44,2    STO 2

014 42,30   NOT

015 42,20   AND

016 45,1    RCL 1

017 45,2    RCL 2

018 42,20  AND

019 42,40   OR

020 43,21   RTN


// Implication

021 43,22,d LBL D

022 34      x<>y

023 42,30   NOT

024 42,40   OR

025 43,21   RTN


// Factorial

026 43,22,E LBL E

027 44,32  STO I

028 1      1

029 44,1    STO 1

030 43,22,1 LBL 1

031 45,1    RCL 1

032 45,32   RCL I

033 20      ×

034  44,1    STO 1

035 43,23   DSZ

036 22,1    GTO 1

037 45,1    RCL 1

038 43,21   RTN


Examples


Let:

R1 = 1011 0001

R2 = 1100 1100


Set up: 2-16-0000 (2's complement, 16 bits)


RCL 2, RCL 1, GSB A NAND(R2, R1):  0111 1111*

RCL 2, RCL 1, GSB B NOR(R2, R1): 0000 0010*

RCL 2, RCL 1, GSB C XNOR(R2, R1): 1000 0010*

RCL 2, RCL 1, GSB D R2 → R1:  1100 1110* 

* only the last eight bits 


Set word size to 64:

0 [ f ] [ STO ] (WSIZE)


5 GSB E 5! = 120

9 GSB E 9! = 362880*


* if the word size is insufficient, it will not show 362880 but a weird result as an overflow


12 GSB E   (64 word size)

12! = 4 79001600

Window 1:  4

Window 0:  79001600


20 GSB E

20! = 243 29020081 76640000

Window 2: 243

Window 1: 29020081

Window 0: 76640000


Source for the Advanced Boolean Functions:


John W. Harris and Horst Stocker.  Handbook of Mathematics and Computation Science  Springer:  New York, NY.  2006.  ISBN 978-0-387-94746-4



Eddie


All original content copyright, © 2011-2021.  Edward Shore.   Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited.  This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author. 


Monday, February 15, 2021

Review: Swiss Micros DM16L

Review: Swiss Micros DM16L






Welcome to a special Monday edition of Eddie’s Math and Calculator blog!


General Information


Company:  SwissMicros, https://www.swissmicros.com

Type:  Programmable Scientific - Boolean Algebra

Memory: 203 steps, shared with memory registers; 32 MB external flash

Battery:  CR 2032

Connection:  USB-B

Cost:  119 CHF, about $132.38 USD (2/5/2021)

Current Software Version:  DM16_31, 7/21/2020

Case Included?  Yes

Operating System: RPN (Reverse Polish Notation)


A Programmer’s Paradise

The Swiss Micros DM16L, and it’s small version, the DM16, is a clone of the highly popular and sought after Hewlett Packard HP 16C.  The functions are suited to computer science, including:


One key conversions between Hexadecimal (base 16), Octal (base 8), Decimal (base 10), and Binary (base 2) integers.  


Boolean features including AND, OR, NOT,  XOR


Bit shift and rotating functions, masking bits, and double division, remainder, and multiplication


There is a separate floating point arithmetic mode, separate from decimal integer mode.


You can customize integers up to 64 bits by the WSIZE function.  A handy shortcut is to set integers up to 64 bits is done by the key sequence:  0 [ f ] [ STO ] (WSIZE)


Negation of integers are determined by one of three modes:  1’s Complement, 2’s Complement, and Unsigned Numbers.    


If that isn’t enough, you can manipulate and test specific bits with the SB (set bit), CB (clear bit), and B? (is the bit set) commands. 


The STATUS command gives the user a three number status #-##-####. 


The first number is the complement mode:  0 for unsigned, 1 for 1’s complement, 2 for 2’s complement.


The second number is the current wordsize, from 1 bit to 64 bits.


The third number is the status of the four user flags 0 to 3, in descending order (flag 3, flag 2, flag 1, flag 0):  0 for clear, 1 for set.  The user flags are used in programming.


Programming


If you have programmed on the original HP-16C, then you would be right at home programming with the DM16L, with all the key codes and positions intact.   There are eight comparison tests available:  x≤y, x<0, x>y, x>0, x≠y, x≠0, x=y, x=0.   Up to 16 labels can be used, labels 0-F.  The special registers I and (I) are used for indirect storage and branching.   The DSE and ISZ use register I.


Curiously missing is storage arithmetic.   For example, instead of STO+ #, the following sequence of commands must be used:  (number), RCL #, +, STO #.  


Sample Programs


Integer Division:  Quotient and Remainder


001 LBL A         43,22,A

002 STO 0 44,0

003 X<>Y 34

004 STO 1 44, 1

005 X<>Y 34

006 ÷ 10

007 R/S 31

008 RCL 1 45, 1

009 RCL 0 45, 0

010 RMD 42, 9   \\ remainder command

011 RTN 43, 21


Example:  Word size = 16


Decimal Integer Mode (DEC):   41 / 7 = 5, remainder 6

Y:  41, X:  7 [ GSB ] [ A ]

Result:   5, [ R/S ], 6


Hexadecimal Integer Mode (HEX):  FE2 / 81 = 1F, remainder 43

Y:  FE2, X: 81 [ GSB ] [ A ]

Result:  1F, [ R/S ], 43


Adding Both the 1’s and 2’s Complement


001 LBL B 43, 22, B

002 STO 1 44, 1

003 Set 1’s 42, 1

004 CHS 49

005 STO 0 44, 0

006 RCL 1 45, 1

007 Set 2’s 42, 2

008 CHS 49

009 RCL 0 45, 0   // storage arithmetic is not available

010 + 40

011 STO 0 44, 0

012 RTN 43, 21


Examples:  Word Size = 8


Hexadecimal Integer Mode (HEX)

x = 2D

Result:  A5  (D2 + D3)


Hexadecimal Integer Mode (HEX)

x = F6

Result:  13  (9 + A)


Remember: Word size is important, as your mileage may vary.  


Verdict

Swiss Micros continues to manufacture quality calculators.  Due to the rarity and highly sought after HP 16C, the price to obtain one may be out of reach.  The DM16L is a much more affordable alternative.  The calculator is solid, keys feel great, and the added connectivity is an added bonus.  


Eddie


All original content copyright, © 2011-2021. Edward Shore.   Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited.  This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author. 


DM42 and HP 42S: Quadratic Equation, Characteristic Polynomial, and Eigenvalues

DM42 and HP 42S: Quadratic Equation, Characteristic Polynomial, and Eigenvalues The programs are listed for the Swiss Micros DM42 an...