Masskiing Ottt E E - HP -16C Owner's Handbook Manual

Table of Contents

Advertisement

Section 4: Arithmetic and Bit Manipulation Functions
51
Testing for the presence of a given bit ([f](B?]) is a conditional test
useful in programming: a decision for program execution can be
based on the bit pattern of a number. (The X- and Y-registers must
contain the proper parameters, as noted above.) Section 9 describes
conditional branching.
Masking
The
(mask left) and
(mask right) functions create
left- or right-justified strings of 1 bits. The magnitude of the
number in the X-register is used to determine how many 1's will
comprise the mask. Upon execution, the mask pattern is placed in
the X-register (the stack does not move).
You can create a mask as large as the word size. To place a mask in
the middle of the field of a number, use a shift function in
conjunction with [MASKL or [MASKR].
Example: The ASCII representation of a two-digit number
occupies 16 bits—eight bits per digit. Given an ASCII "65" (0011
01100011 0101), extract the high-order digit (6), thereby converting
half of this ASCII code to binary coded decimal.
0011 0110 0011 0101 ASCII"65" ("3","6", "3", "5").
0000 1111 0000 0000 Mask.
0000 0110 0000 0000 The extracted, high-order digit ("6").
You can save keystrokes in this example by shifting the digits into
position before masking.
Keystrokes
Display
([STATUS]: 2-16-0000)
3635
3635 h
8
3536 h
Rotates word eight bits
to the right to right-
justify the desired hex
digit (6).
4
F h
Right-justifies a mask of
four 1 bits (1111) in the
16-bit word.
6 h
Extracts the rightmost
four bits (6).

Advertisement

Table of Contents
loading

Table of Contents