# can i convert Numerics data types into Flags?

F

#### Felipe Sanchez A. (Chile)

In CL/HPM lenguage i need to know how can i convert Numerics data types into Flags.

A

#### Anonymous

easy solution: if statements. if u are afraid errors failing your CL, use logic points which i recommend over CL anyway.

B

#### Bill

<p>This sample should get you started. It will decode 4 binary flags (FLGx) from a single bitmask value (NUMVALUE.PV) in the range of 0 to 15 (2^4 - 1 = 15). The bitmask could be expanded as large as necessary using an array and loop statements if more flags are needed.
<pre>
---------------------------------------
--Decode flags from numeric data
-- Data is a bitmask for 4 flags:
-- FLG1=2^0, FLG2=2^1, FLG3=2^2, FLG4=2^3

--Set a temporary value for use in decoding
set i = NUMVALUE.PV

--Starting with highest bit (2^3), set flags
-- and reduce temporary value
if i>=8 then (set FLG4 = ON; set i = i-8)
else set FLG4 = OFF
if i>=4 then (set FLG3 = ON; set i = i-4)
else set FLG3 = OFF
if i>=2 then (set FLG2 = ON; set i = i-2)
else set FLG2 = OFF
if i>=1 then (set FLG1 = ON; set i = i-1)
else set FLG1 = OFF
</pre>

Y

#### yoga

<p>Hi, Felipe

<p>This the answer I got from my colleague.

<p>May you use this statement to convert Numerics into Flags (You have to assign a threshold value, in this example, the threshold value is 0 (zero) :
<pre>
LOCAL FLAG : LOGICAL AT !BOX.FL(001)
LOCAL NUMERIC : NUMBER AT !BOX.NN(001)

SET FLAG = (WHEN NUMERIC = 0 : OFF ; WHEN OHERS : ON)
</pre>
<p>Threshold is a transition value you want to extinguish the status. It can be any value.

<p>Wish it helps!