Showing posts with label or. Show all posts
Showing posts with label or. Show all posts

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. 


Sunday, June 21, 2020

TI-84 Plus CE: Bitwise Operations

TI-84 Plus CE:  Bitwise Operations

Introduction

The programs NOT, AND, OR, and XOR are presented for the TI-84 Plus CE for integer in decimal base.

NOT

For integers x > 0, the NOT function is defined as:

Σ( 2^n * ( floor(x/2^n) mod 2 + 1 ) mod 2 ) from n = 0 to floor(log(x)/log(2))

However, observing the NOT operation on scientific calculators, the not function can  be used for integers:

-(x + 1)

TI-84 Plus CE Program NOT

"2020-05-11 EWS"
Disp "NOT(X), X>0"
Prompt X
­(X+1)→N
Disp "NOT X = ",N

Examples:

NOT 192:  Returns -193

NOT -52:  Returns 51

AND

For positive integers x, y and for x ≥ y, the AND function is defined as:

Σ( 2^n * ( [ floor(x/2^n) mod 2 ] * [ floor(y/2^n) mod 2 ] ) from n = 0 to floor(log(x)/log(2))


TI-84 Plus CE Program AND

"2020-05-11 EWS"
Disp "X AND Y, X≥Y"
Prompt X,Y
0→T
For(N,0,X-fPart(X))
(X/2^N)-fPart(X/2^N)→A
2*fPart(A/2)→A
(Y/2^N)-fPart(Y/2^N)→B
2*fPart(B/2)→B
T+2^N*A*B→T
End
Disp T

Examples:

145 AND 37:  Returns 1

226 AND 125:  Returns 96

OR

For positive integers x, y and for x ≥ y, the OR function is defined as:

Σ( 2^n *
[ [ ( floor(x/2^n) mod 2) + ( floor(y/2^n) mod 2 ) + ( floor(x/2^n) mod 2 * floor(y/2^n) mod 2) ] mod 2 ] from n = 0 to floor(log(x)/log(2))

TI-84 Plus CE Program OR

"2020-05-11 EWS"
Disp "X OR Y, X≥Y"
Prompt X,Y
0→T
For(N,0,X-fPart(X))
(X/2^N)-fPart(X/2^N)→A
2*fPart(A/2)→A
(Y/2^N)-fPart(Y/2^N)→B
2*fPart(B/2)→B
T+2^N*2*fPart((A+B+A*B)/2)→T
End
Disp T

Examples:

145 OR 37:  Returns 181

226 OR 125:  Returns 255

XOR

For positive integers x, y and for x ≥ y, the XOR function is defined as:

Σ( 2^n * [ [ floor(x/2^n) + floor(y/2^n) ] mod 2 ]  from n = 0 to floor(log(x)/log(2))

TI-84 Plus CE Program XOR

"2020-05-11 EWS"
Disp "X XOR Y, X≥Y"
Prompt X,Y
0→T
For(N,0,X-fPart(X))
(X/2^N)-fPart(X/2^N)→A
2*fPart(A/2)→A
(Y/2^N)-fPart(Y/2^N)→B
2*fPart(B/2)→B
T+2^N*2*fPart((A+B)/2)→T
End
Disp T

Examples:

145 XOR 37:  Returns 180

226 XOR 125:  Returns 159

Eddie

Source:

“Bitwise Operation”  Wikipedia.  Page last edited May 10, 2020.  Accessed on May 11, 2020.
Link:  https://en.wikipedia.org/wiki/Bitwise_operation

Eddie

All original content copyright, © 2011-2020.  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.

Saturday, June 20, 2020

HP 41C: Decimal Bitwise Operations

HP 41C: Decimal Bitwise Operations

The document covers the following operations:

NOT:  for integers
AND:  for positive integers
OR:  for positive integers
XOR:  for positive integers
Simple conversions between Binary and Decimal bases (integers up to 1023)

No extra or additional modules required.  Should work for the Swiss Micros DM41 and any emulators.

Download the PDF here: https://drive.google.com/file/d/1g7fhB4ehH0CNMizKOGpZ7bJTcLfBIVUA/view?usp=sharing

Eddie

All original content copyright, © 2011-2020.  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.

Saturday, April 25, 2020

HP 42S/DM42/Free 42: Advanced Boolean Functions

HP 42S/DM42/Free 42: Advanced Boolean Functions

Introduction

The programs NOTBIT, NAND, NOR, and IMPL are four advanced Boolean functions that work on Binary Numbers.  You designate a bit size, up to 35, on each of these functions.   There is no signed bit in these programs.  Results are stored in the Alpha Register while the decimal equivalent is stored in the X register. 

HP 42S/DM42/Free 42 Program:  NOTBIT

00 { 57-Byte Prgm }
01▸LBL "NOTBIT"
02 "BIT SIZE?"
03 PROMPT
04 STO 00
05 BINM
06 "BIN?"
07 PROMPT
08 STO 01
09 DECM
10 2
11 RCL 00
12 Y↑X
13 X<>Y
14 BASE-
15 1
16 BASE-
17 BINM
18 "NOT: "
19 ARCL ST X
20 AVIEW
21 EXITALL
22 .END.

Example:

NOT 11011, bit size:  8

Result: 
NOT:  11100100

HP 42S/DM42/Free 42 Program:  NAND

a NAND b = NOT ( a AND b )

00 { 67-Byte Prgm }
01▸LBL "NAND"
02 "BIT SIZE?"
03 PROMPT
04 STO 00
05 BINM
06 "BIN1?"
07 PROMPT
08 STO 01
09 "BIN2?"
10 PROMPT
11 STO 02
12 AND
13 DECM
14 2
15 RCL 00
16 Y↑X
17 X<>Y
18 BASE-
19 1
20 BASE-
21 BINM
22 "NAND: "
23 ARCL ST X
24 AVIEW
25 EXITALL
26 .END.

Example:

110011 NAND 111100, bit size: 8

Result:
NAND:  11001111

HP 42S/DM42/Free 42 Program:  NOR

a NOR b = NOT ( a OR b )

00 { 64-Byte Prgm }
01▸LBL "NOR"
02 "BIT SIZE"
03 PROMPT
04 STO 00
05 BINM
06 "BIN1?"
07 PROMPT
08 STO 01
09 "BIN2?"
10 PROMPT
11 STO 02
12 OR
13 DECM
14 2
15 RCL 00
16 Y↑X
17 X<>Y
18 BASE-
19 1
20 BASE-
21 BINM
22 "NOR: "
23 ARCL ST X
24 AVIEW
25 EXITALL
26 .END.

Example:

110011 NOR 111100, bit size: 8

Result:
NOR:  11000000

HP 42S/DM42/Free 42 Program:  IMPL

IMPL (Implication):  a → b = (NOT a) OR b

00 { 66-Byte Prgm }
01▸LBL "IMPL"
02 "BIT SIZE?"
03 PROMPT
04 STO 00
05 BINM
06 "BIN1?"
07 PROMPT
08 STO 01
09 DECM
10 2
11 RCL 00
12 Y↑X
13 X<>Y
14 BASE-
15 1
16 BASE-
17 BINM
18 "BIN2?"
19 PROMPT
20 STO 02
21 OR
22 "A→B: "
23 ARCL ST X
24 AVIEW
25 EXITALL
26 .END.

Example:

110011 IMPL 111100, bit size: 8

Result:
IMPL:  11111100

You can download the raw files here: 
https://drive.google.com/open?id=19u8tPcX4_-o0lwvjUc0KO4-WSmhnxpwe

Source:

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-2020.  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, March 8, 2020

HP Prime: Advanced Boolean Functions

Advanced Boolean Functions





This is a collection of advanced Boolean functions and how you can do this on a scientific calculator that has base conversions and Boolean functions (and, or, not).   One thing to keep in mind is that Boolean functions on a scientific calculator assume that you are working with a set bit size.

Order of Operations:  Parenthesis, NOT, AND, OR

For the examples below, I am going to work with only 8 bit size binary integers, and display the last 8 bits (rightmost 8 digits in Binary numbers).   For all examples, let (in base 2):

A = 1100 1010
B = 1110 0011

Like the Boolean functions and, or, and not, these functions work on each bit (0s and 1s) of the binary form of the number.

Integer Types on the HP Prime

On the HP Prime, the integer type is used for Boolean function calculations.  Symbolize integer types by preceding it by a hashtag # and designated a letter at the end of the integer:  b for binary, o for octal, d for decimal, and h for hexadecimal.

Example:  #11010b  represents the binary number 11010.

You can specify the bit size, from 1 to 64, by attaching a colon and bit size in between the integer and it's indicator.

Example:  #11010:8b represents the 11010 in an 8-bit format.  You can specify the default size in the Home Settings.

NAND (Not And)

The function NAND is also known as the Shaffer function.

nand(A, B) = not(A and B)

nand(1100 1010, 1110 0011) = not(1100 1010 and 1110 0011) = 0011 1101

Truth Table - NAND
0 nand 0 = 1
0 nand 1 = 1
1 nand 0 = 1
1 nand 1 = 0

HP Prime Program:  NAND

EXPORT NAND(a,b)
BEGIN
// not and Boolean Function
RETURN  NOT (a AND b);
END;

Syntax:  NAND(a,b)

NOR (Not Or)

The function NOR is also known as the Peirce function.

nor(A, B) = not(A or B)

nor(1100 1010, 1110 0011) = not(1100 1010 or 1110 0011) = 0001 0100

Truth Table - NOR
0 nor 0 = 1
0 nor 1 = 0
1 nor 0 = 0
1 nor 1 = 0

HP Prime Program:  NOR

EXPORT NOR(a,b)
BEGIN
// not or Boolean Function
RETURN  NOT (a  OR  b);
END;

Syntax:  NOR(a,b)

XOR (Exclusive Or)

Note:  some calculators will have the XOR function

xor(A, B) = (A or B) and (not A or not B)

xor(1100 1010, 1110 0011)
= (1100 1010 or 1110 0011) and (not 1100 1010 or not 1110 0011)
= 0010 1001

Truth Table - XOR
0 xor 0 = 0
0 xor 1 = 1
1 xor 0 = 1
1 xor 1 = 0

Equivalence (←→), XNOR

A ←→ B = (not A and not B) or (A and B)

1100 1010 ←→ 1110 0011
= 1100 1010 xnor 1110 0011
= (not 1100 1010 and not 1110 0011) or (1100 1010 and 1110 0011)
= 1101 0110

Truth Table - ←→, xnor 
0 xnor 0 = 1
0 xnor 1 = 0
1 xnor 0 = 0
1 xnor 1 = 1

HP Prime Program XNOR

EXPORT XNOR(a,b)
BEGIN
// equivalence, XNOR
RETURN (NOT a AND NOT b) or (a AND b);
END;

Syntax:  XNOR(a, b)

Implication (→)

A → B = (not A) or B

1100 1010 → 1110 0011
= (not 1100 1010) or 1110 0011
= 1111 0111

Truth Table -  Implication, →
0 → 0 = 1
0 → 1 = 1
1 → 0 = 0
1 → 1 = 1

HP Prime Program:  IMPL

EXPORT IMPL(a,b)
BEGIN
// implication
RETURN (NOT a) or b;
END;

Source:

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-2020.  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.

Thursday, May 3, 2012

Logic Operators and the TI-36X Pro

Introduction

This blog entry is in response to a email regarding the logic operations I received from jcroot on the Texas Instruments TI-36X Pro Review: (link here)

Hello Eddie!

How are you today? I was just wondering if you could please give us an example of how to use the "Logic function" on this calculator, I am trying to follow the manual but I still can't understand in which situations this could be useful.


jcroot, I hope that this blog entry (at least in part) answers your question. I had to research a bit because I must confess that I do not use logic operators much on calculators.

Logic Operators

The most common logic operators are: and, or, not, 2's compliment and xor. The TI-36X has two additional operators xnor and nand. The latter two are not common on calculators.

I tend to think binary numbers as the prime example for these logic operators. It is my understanding that the operators compare the binary form (base 2 integers) of an integer and if necessary, convert the answer back into the required form (decimal, hexadecimal, or octal).

Binary Numbers

Binary numbers are numbers consisting of 0 and 1, with each digit being a bit. Often, the bit 0 is referred to "off" or "false", while the bit 1 is referred to "on" or "true". Each bit resembles a power of 2, with powers of 2 increasing from right to left:

...(2^n)...(2^5)(2^4)(2^3)(2^2)(2^1)(2^0)

For example, if the first (rightmost bit) is 1, then the value "1" is turned on. If the second bit is 1, then the value "2" is turned on, the third bit gives a value of "4", fourth bit gives a value of "8", and so on. Binary numbers are often written with a subscript of 2. On calculators, they are often designated with b or a "#b".

On the TI-36X Pro

Change to BINary Mode: Press [mode], arrow down five times, select BIN, hit [enter], then [2nd] [mode] (quit). You can designate DECimal (normal - base 10), HEXadecimal (base 16), and OCTal (base 8) modes in a similar way.

Designate a binary number in any mode: type your binary number, [2nd] [ 9 ] (base n), select TYPE, select 2: b. This procedure is not necessary if you are in Binary Mode.

[2nd] [ 9 ] (base n) gives you access to conversions (CONV), designations (TYPE), and operations (LOGIC).

One Argument Logic Operators

not: This operator basically switches a bit. In binary numbers, if the bit is 0, then not 0 = 1. Similarly, if the bit is 1, then not 1 = 0.

2's Complement: This complement is a way to manipulate binary numbers such that the arithmetic, specifically addition and subtraction of binary numbers, is accurate. More information is found by clicking on this sentence.

Two Argument Logic Operators

The following logic operations answer different types of questions:

and: Are both bit 1 true and bit 2 true?

or (inclusive or): Is either bit 1 or bit 2 true? Bit 1 and bit 2 can both be true.

xor (exclusive or): Is either bit 1 true or bit 2 true - without both bits being true?

xnor (not exclusive or): The opposite of xor. Are both bits true or both bits false?

nand (not and): The opposite of and. Is at least one of the bits false?

The following table summaries and, or, xor, xnor, and nand.

How the TI-36X Works With Binary Numbers

All binary numbers work with 10 bit integers. Attempting to work integers greater than 10 bits causes a SYNTAX Error. This error is not mentioned in the TI-36X Manual.

The binary number of a TI-36X looks like this:

##########

where # is a 0 or 1. If you enter less than 10 bits, the calculator "fills" the leftmost bits with 0. Note that I designated the leftmost bit (10th bit) red and bold. This is known as the sign bit. If this bit is 0, then the integer is positive.

(sign) (2^8) (2^7) (2^6) (2^5) (2^4) (2^3) (2^2) (2^1) (2^0)
0 [ 1 = "on", 0 = "off"]

However, if the leftmost bit (10th bit) is 1, then the integer is negative. I am not 100% sure how the rest of the bits are designated.

Note in all examples, I designate binary numbers with the "b", like the calculator does.

10001b = 0000010001b = 17

1111101111b = -17

For the TI-36X Pro, the boundary for binary integers in the interval [-511, 511].
(2^9 - 1 = 511) Remember, the 10th bit is the sign bit on this calculator.

When using logic operators, the TI-36X compares each bit, including the 10th bit.

By the way, binary integers can be stored and recalled in variables.

Examples:

Let x = 0000011101b (5th, 4th, 3rd, and 1st bits are on, x = 29)
and y = 0000010100b (5th and 3rd bits are on, y = 20)

(decimal equivalents in parenthesis)
x and y = 0000010100b (29 and 20 = 20)
x or y = 0000011101b (29 or 20 = 29)
x xor y = 0000001001b (29 xor 20 = 9)
x xnor y = 1111110110b (29 xnor 20 = -10)
x nand y = 1111101011b (29 nand 20 = -21)

So, when I think of logic operations, I think of comparing binary numbers (or binary equivalent of integers) bit by bit, given a designated amount of bits.

Hope this helps,

Eddie.



This blog is property of Edward Shore. © 2012

RPN HP 12C: Fibonacci and Lucas Sequences

  RPN HP 12C: Fibonacci and Lucas Sequences Golden Ratio, Formulas, and Sequences Let φ be the Golden Ratio: φ = (1 + √5) ÷ 2...