Showing posts with label binary integers. Show all posts
Showing posts with label binary integers. 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, 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. 


Trigonometry Reduction Formula and Solving Simple Arcsine and Arccosine Equations

Trigonometry Reduction Formula and Solving Simple Arcsine and Arccosine Equations Some Background and Periodic Reduction Formulas ...