xHarbour Reference Documentation > Function Reference xHarbour Developers Network  

I2Bin()

Converts a numeric value to a signed short binary integer (2 bytes).

Syntax

I2Bin( <nNumber> ) --> cInteger

Arguments

<nNumber>
A numeric value in the range of -(2ˆ15) to +(2ˆ15) - 1.

Return

The function returns a two-byte character string representing a 16-bit signed short binary integer.

Description

I2Bin() is a binary conversion function that converts a numeric value (Valtype()=="N") to a two byte binary number (Valtype()=="C").

The range for the numeric return value is determined by a signed short integer. If <nNumber> is outside this range, a runtime error is raised.

I2Bin() is the inverse function of Bin2I().

Info

See also:Asc(), Bin2I(), Bin2L(), Bin2U(), Bin2W(), Chr(), L2Bin(), U2Bin(), W2Bin()
Category: Binary functions , Conversion functions
Source:rtl\binnum.c
LIB:xhb.lib
DLL:xhbdll.dll

Example

// The example demonstrates return values of I2Bin().

   PROCEDURE Main
      LOCAL cInt

      cInt := I2Bin(0)
      ? Asc( cInt[1] ), Asc( cInt[2] )  // result:   0    0

      cInt := I2Bin(1)
      ? Asc( cInt[1] ), Asc( cInt[2] )  // result:   1    0

      cInt := I2Bin(-1)
      ? Asc( cInt[1] ), Asc( cInt[2] )  // result: 255  255

      cInt := I2Bin(256)
      ? Asc( cInt[1] ), Asc( cInt[2] )  // result:   0    1

      cInt := I2Bin(-256)
      ? Asc( cInt[1] ), Asc( cInt[2] )  // result:   0  255

      cInt := I2Bin(32767)
      ? Asc( cInt[1] ), Asc( cInt[2] )  // result: 255  127

      cInt := I2Bin(-32768)
      ? Asc( cInt[1] ), Asc( cInt[2] )  // result:   0  128

   RETURN

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