xHarbour Reference Documentation > Function Reference xHarbour Developers Network  

BitToC()

Translates bits of an integer to a character string.

Syntax

BitToC( <nInteger>   , ;
        <cBitPattern>, ;
       [<lSpaces>]     ) --> cResult

Arguments

<nInteger>
This is a numeric integer value in the range of 0 to 65535.
<cBitPattern>
This is a character string of max. 16 characters used as bit pattern.
<lSpaces>
If set to .T. (true), blank spaces are inserted in the result string for zero bits. The default value is .F. (false).

Return

The function returns a character string containing the characters of <cBitPattern> which are located at the same position as a bit set in <nInteger>. When <lSpaces> is .T. (true), the return string includes blank spaces at the position of unset bits. When it is .F. (false), unset bits of <nInteger> are not included in the return string.

Info

See also:CtoBit(), CtoN(), HB_BitIsSet()
Category: CT:NumBits , Bitwise functions , Numbers and Bits
Source:ct\numconv.prg
LIB:xhb.lib
DLL:xhbdll.dll

Example

// The example displays results of BitToC() in comparison to
// the binary representation of a number

   PROCEDURE Main

      // binary representation of 11
      ? NtoC( 11, 2, "0" )          // result: 1011

      // zero bit is ingnored
      ? BitToC( 11, "ABCD" )        // result: ACD

      // zero bit yields blank space
      ? BitToC( 11, "ABCD", .T. )   // result: A CD
   RETURN

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