169 lines
9.8 KiB
HTML
169 lines
9.8 KiB
HTML
|
<?xml version="1.0" encoding="UTF-8"?>
|
||
|
<!DOCTYPE html
|
||
|
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||
|
<html lang="en-us" xml:lang="en-us">
|
||
|
<head>
|
||
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||
|
<meta name="security" content="public" />
|
||
|
<meta name="Robots" content="index,follow" />
|
||
|
<meta http-equiv="PICS-Label" content='(PICS-1.1 "http://www.icra.org/ratingsv02.html" l gen true r (cz 1 lz 1 nz 1 oz 1 vz 1) "http://www.rsac.org/ratingsv01.html" l gen true r (n 0 s 0 v 0 l 0) "http://www.classify.org/safesurf/" l gen true r (SS~~000 1))' />
|
||
|
<meta name="DC.Type" content="reference" />
|
||
|
<meta name="DC.Title" content="%BINARY built-in function" />
|
||
|
<meta name="abstract" content="The binary built-in function (%BINARY or %BIN) interprets the contents of a specified CL character variable as a signed binary integer." />
|
||
|
<meta name="description" content="The binary built-in function (%BINARY or %BIN) interprets the contents of a specified CL character variable as a signed binary integer." />
|
||
|
<meta name="DC.subject" content="%BINARY (binary) built-in function, description, %BIN (binary) function, binary function, example, BIN function" />
|
||
|
<meta name="keywords" content="%BINARY (binary) built-in function, description, %BIN (binary) function, binary function, example, BIN function" />
|
||
|
<meta name="DC.Relation" scheme="URI" content="contp.htm" />
|
||
|
<meta name="DC.Relation" scheme="URI" content="valuv.htm" />
|
||
|
<meta name="DC.Relation" scheme="URI" content="../clfinder/finder.htm" />
|
||
|
<meta name="DC.Relation" scheme="URI" content="../cl/if.htm" />
|
||
|
<meta name="DC.Relation" scheme="URI" content="../cl/chgvar.htm" />
|
||
|
<meta name="DC.Relation" scheme="URI" content="../cl/callprc.htm" />
|
||
|
<meta name="DC.Relation" scheme="URI" content="../cl/sndpgmmsg.htm" />
|
||
|
<meta name="DC.Relation" scheme="URI" content="rbam6builtinfunc.htm" />
|
||
|
<meta name="copyright" content="(C) Copyright IBM Corporation 1998, 2006" />
|
||
|
<meta name="DC.Rights.Owner" content="(C) Copyright IBM Corporation 1998, 2006" />
|
||
|
<meta name="DC.Format" content="XHTML" />
|
||
|
<meta name="DC.Identifier" content="binar" />
|
||
|
<meta name="DC.Language" content="en-us" />
|
||
|
<!-- All rights reserved. Licensed Materials Property of IBM -->
|
||
|
<!-- US Government Users Restricted Rights -->
|
||
|
<!-- Use, duplication or disclosure restricted by -->
|
||
|
<!-- GSA ADP Schedule Contract with IBM Corp. -->
|
||
|
<link rel="stylesheet" type="text/css" href="./ibmdita.css" />
|
||
|
<link rel="stylesheet" type="text/css" href="./ic.css" />
|
||
|
<title>%BINARY built-in function</title>
|
||
|
</head>
|
||
|
<body id="binar"><a name="binar"><!-- --></a>
|
||
|
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
|
||
|
<h1 class="topictitle1">%BINARY built-in function</h1>
|
||
|
<div><p>The binary built-in function (%BINARY or %BIN) interprets the contents
|
||
|
of a specified CL character variable as a signed binary integer. </p>
|
||
|
<div class="section"><p>The starting position begins at the position specified and continues
|
||
|
for a length of 2 or 4 characters.</p>
|
||
|
<p>The syntax of the binary built-in
|
||
|
function is shown in the following example: </p>
|
||
|
<pre>%BINARY(character-variable-name starting-position length)</pre>
|
||
|
<p>You can also code it like this example:</p>
|
||
|
<pre>%BIN(character-variable-name starting-position length)</pre>
|
||
|
<p>The starting position and length are optional. However, if
|
||
|
the starting position and length are <em>not specified</em>, a starting position
|
||
|
of 1 and length of the character variable that is specified are used. In that
|
||
|
case, you must declare the length of the character variable as either 2 or
|
||
|
4.</p>
|
||
|
<p>If the starting position <em>is specified</em>, you must also specify
|
||
|
a constant length of 2 or 4. The starting position must be a positive number
|
||
|
equal to or greater than 1. If the sum of the starting position and the length
|
||
|
is greater than the length of the character variable, an error occurs. (A
|
||
|
CL decimal or integer variable may also be used for the starting position.)</p>
|
||
|
<p>You
|
||
|
can use the binary built-in function with both the <span class="cmdname">If (IF)</span> and <span class="cmdname">Change
|
||
|
Variable (CHGVAR)</span> commands. It can be used by itself or as part
|
||
|
of an arithmetic or logical expression. You can also use the binary built-in
|
||
|
function on any command parameter that is defined as numeric (TYPE of *DEC,
|
||
|
*INT2, *INT4, *UINT2, or *UINT4) with EXPR(*YES).</p>
|
||
|
<p>When the binary built-in
|
||
|
function is used with the condition (COND) parameter on the IF command or
|
||
|
with the VALUE parameter on the <span class="cmdname">Change Variable (CHGVAR)</span> command,
|
||
|
the contents of the character variable is interpreted as a binary-to-decimal
|
||
|
conversion.</p>
|
||
|
<p>When the binary built-in function is used with the VAR parameter
|
||
|
on the <span class="cmdname">Change Variable (CHGVAR)</span> command, the decimal value
|
||
|
in the VALUE parameter is converted to a 2-byte or 4-byte signed binary integer
|
||
|
and the result stored in the character variable at the starting position specified.
|
||
|
Decimal fractions are truncated.</p>
|
||
|
<p>The system uses the binary built-in
|
||
|
function on the RTNVAL parameter of the <span class="cmdname">Call Bound Procedure (CALLPRC)</span> command
|
||
|
to indicate that the calling procedure expects the called procedure to return
|
||
|
a signed binary integer.</p>
|
||
|
<p>A 2-byte character variable can hold signed
|
||
|
binary integer values from -32 768 through 32 767. A 4-byte character variable
|
||
|
can hold signed binary integer values from -2 147 483 648 through 2 147 483
|
||
|
647.</p>
|
||
|
<p>The following are examples of the binary built-in function:</p>
|
||
|
<ul><li> <pre>DCL VAR(&B2) TYPE(*CHAR) LEN(2) VALUE(X'001C')
|
||
|
DCL VAR(&N) TYPE(*DEC) LEN(3 0)
|
||
|
CHGVAR &N %BINARY(&B2)</pre>
|
||
|
<p>The contents of variable &B2 is treated as a 2-byte signed
|
||
|
binary integer and converted to its decimal equivalent of 28. It is then
|
||
|
assigned to the decimal variable &N</p>
|
||
|
</li>
|
||
|
<li> <pre>DCL VAR(&N) TYPE(*DEC) LEN(5 0) VALUE(107)
|
||
|
DCL VAR(&B4) TYPE(*CHAR) LEN(4)
|
||
|
CHGVAR %BIN(&B4) &N</pre>
|
||
|
<p>The value of the decimal variable &N is converted to a
|
||
|
4-byte signed binary number and is placed in character variable &B4 Variable &B4
|
||
|
will have the value of <span>X'0000006B'</span>.</p>
|
||
|
</li>
|
||
|
<li> <pre>DCL VAR(&P) TYPE(*CHAR) LEN(100)
|
||
|
DCL VAR(&L) TYPE(*DEC) LEN(5 0)
|
||
|
CHGVAR &L VALUE(%BIN(&P 1 2) * 5)</pre>
|
||
|
<p>The first two characters of variable &P is treated as a
|
||
|
signed binary integer, converted to its decimal equivalent, and multiplied
|
||
|
by 5. The product is assigned to the decimal variable &L.</p>
|
||
|
</li>
|
||
|
<li> <pre>DCL VAR(&X) TYPE(*CHAR) LEN(50)
|
||
|
CHGVAR %BINARY(&X 15 2) VALUE(122.56)</pre>
|
||
|
<p>The number 122.56 is truncated to the whole number 122 and
|
||
|
is then converted to a 2-byte signed binary integer and is placed at positions
|
||
|
15 and 16 of the character variable &X. Positions 15 and 16 of variable &X
|
||
|
will contain the hexadecimal equivalent of <span>X'007A'</span>.</p>
|
||
|
</li>
|
||
|
<li> <pre>DCL VAR(&B4) TYPE(*CHAR) LEN(4)
|
||
|
CHGVAR %BIN(&B4) VALUE(-57)</pre>
|
||
|
<p>The value -57 is converted to a 4-byte signed binary integer
|
||
|
and assigned to the character variable &B4. The variable &B4 will
|
||
|
then contain the value <span>X'FFFFFFC7'</span>.</p>
|
||
|
</li>
|
||
|
<li> <pre>DCL VAR(&B2) TYPE(*CHAR) LEN(2) VALUE(X'FF1B')
|
||
|
DCL VAR(&C5) TYPE(*CHAR) LEN(5)
|
||
|
CHGVAR &C5 %BINARY(&B2)</pre>
|
||
|
<p>The contents of variable &B2 is treated as a 2-byte signed
|
||
|
binary integer and converted to its decimal equivalent of -229. The number
|
||
|
is converted to character form and stored in the variable character &C5.
|
||
|
The character variable &C5 will then contain the value '-0229'.</p>
|
||
|
</li>
|
||
|
<li> <pre>DCL VAR(&C5) TYPE(*CHAR) LEN(5) VALUE(' 1253')
|
||
|
DCL VAR(&B2) TYPE(*CHAR) LEN(2)
|
||
|
CHGVAR %BINARY(&B2) VALUE(&C5)</pre>
|
||
|
<p>The character number 1253 in character variable &C5 is
|
||
|
converted to a decimal number. The decimal number 1253 is then converted
|
||
|
to a 2-byte signed binary integer and stored in the variable &B2. The
|
||
|
variable &B2 will then have the value <span>X'04E5'</span>.</p>
|
||
|
</li>
|
||
|
<li> <pre>DCL VAR(&S) TYPE(*CHAR) LEN(100)
|
||
|
IF (%BIN(&S 1 2) *GT 10)
|
||
|
THEN( SNDPGMMSG MSG('Too many in list.') )</pre>
|
||
|
<p>The first 2 bytes of the character variable &S are treated
|
||
|
as a signed binary integer when compared to the number 10. If the binary
|
||
|
number has a value larger than 10, then the <span class="cmdname">Send Program Message
|
||
|
(SNDPGMMSG)</span> command is run.</p>
|
||
|
</li>
|
||
|
<li> <pre>DCL VAR(&RTNV) TYPE(*CHAR) LEN(4)
|
||
|
CALLPRC PRC(PROCA) RTNVAL(%BIN(&RTNV 1 4))</pre>
|
||
|
<p>Procedure PROCA returns a 4-byte integer which is stored in
|
||
|
variable &RTNV.</p>
|
||
|
</li>
|
||
|
</ul>
|
||
|
</div>
|
||
|
</div>
|
||
|
<div>
|
||
|
<div class="familylinks">
|
||
|
<div class="parentlink"><strong>Parent topic:</strong> <a href="contp.htm" title="You can use commands to change the flow of logic within your CL procedure.">Control processing within a CL procedure</a></div>
|
||
|
</div>
|
||
|
<div class="reltasks"><strong>Related tasks</strong><br />
|
||
|
<div><a href="valuv.htm" title="You can change the value of a CL variable using the Change Variable (CHGVAR) command.">Change the value of a variable</a></div>
|
||
|
</div>
|
||
|
<div class="relref"><strong>Related reference</strong><br />
|
||
|
<div><a href="rbam6builtinfunc.htm" title="CL provides several built-in functions.">Built-in functions for CL</a></div>
|
||
|
</div>
|
||
|
<div class="relinfo"><strong>Related information</strong><br />
|
||
|
<div><a href="../clfinder/finder.htm">CL command finder</a></div>
|
||
|
<div><a href="../cl/if.htm">If (IF) command</a></div>
|
||
|
<div><a href="../cl/chgvar.htm">Change Variable (CHGVAR) command</a></div>
|
||
|
<div><a href="../cl/callprc.htm">Call Bound Procedure (CALLPRC) command</a></div>
|
||
|
<div><a href="../cl/sndpgmmsg.htm">Send Program Message (SNDPGMMSG) command</a></div>
|
||
|
</div>
|
||
|
</div>
|
||
|
</body>
|
||
|
</html>
|