xHarbour Reference Documentation > Operator Reference xHarbour Developers Network  

| (bitwise OR)

Bitwise OR operator (binary): performs a logical OR operation.

Syntax

<cString> | <nMask> --> Character
<cString> | <cMask> --> Character
<nNumber> | <nMask> --> Numeric
<nNumber> | <cMask> --> Numeric

Arguments

<cString>
A character expression of which all bits of each character are processed in a logical OR operation.
<nNumber>
A numeric value all bits of which are processed. Numbers are always treated as integer values. If a number has a decimal fraction, it is truncated.
<nMask>|<cMask>
The right operand of the bitwise OR operator can be specified as a character or a numeric value.

Description

The bitwise OR operator performs a logical OR operation with the individual bits of both operands. The left operand is the value to process while the right operand provides the bit mask for the operation. The return value of the | operator has the same data type as the left operand.

Bits at identical positions in both operands are compared. The bit at the same position is set in the return value, when one of both operands have the bit set at the same position. If either operand has a bit not set, the corresponding bit in the return value is also not set.

The bit mask to apply to the left operand can be specified as a numeric or as a character value. Depending on the left operand, bitwise OR operations are performed according to the following rules:

cString | cMask

When both operands are character values, the bits of individual characters of both operands are compared. If the right operand has less characters, it is repeatedly applied until all characters of the left operand are processed. The return value has the same number of characters as the left operand.

cString | nMask

When the left operand is a character value and the right operand is numeric, the bits set in the numeric value are compared with the bits of each character in the left operand.

nNumber | cMask

When the left operand is numeric and the right operand is a character value, the bits set in the numeric value are compared consecutively with the bits of each character in the right operand.

nNumber | nMask

When both operands are numeric values, the bits of both values are compared.

Note:  Numeric operands are always treated as integer values. If a number has a decimal fraction, it is ignored.

Info

See also:& (bitwise AND), ˆˆ (bitwise XOR), .AND., .NOT., .OR., HB_BitOr()
Category: Bitwise operators , Operators , xHarbour extensions
LIB:xhb.lib
DLL:xhbdll.dll

Example

// The example sets all characters in lower case and performs a bitwise
// OR operation between 123 as character/numeric and 3.

   PROCEDURE Main()

      ? "MiXeD CaSe StRiNg" | 32          // result: mixed case string

      ? "123" | 3                         // result: 333
      // "1" binary: 00110001 | 00000011  => 00110011  "3"
      // "2" binary: 00110010 | 00000011  => 00110011  "3"
      // "3" binary: 00110011 | 00000011  => 00110011  "3"

      ? 123 | 3                           // result: 123
      // 123 binary: 01111011 | 00000011  => 01111011

   RETURN NIL

Copyright © 2006-2007 xHarbour.com Inc. All rights reserved.
http://www.xHarbour.com
Created by docmaker.exe