xHarbour Reference Documentation > Function Reference xHarbour Developers Network  

CharSHR()

Shifts bits in a character string to the right.

Syntax

CharSHR( <cString>, <nShift> ) --> cResult

Arguments

<cString>
This is the character string to process.
<nShift>
This is a numeric integer value indicating how many places the bits of each character of <cString> are shifted to the right.

Return

The function returns a string by shifting the bits of the individual characters of <cString> for <nShift> places to the right. The lowest bit is discarded and the highest bit is set to zero.

Info

See also:>>, CharAND(), CharNOT(), CharOR(), CharRLL(), CharRLR(), CharSHL(), CharXOR(), HB_BitShift()
Category: CT:String manipulation , Bitwise functions , Character functions , xHarbour extensions
Source:ct\charop.c
LIB:xhb.lib
DLL:xhbdll.dll

Example

// The example demonstrates the effect of shifting bits in
// a two-character string, by displaying the ASCII codes and
// their binary representation before and after the right shift
// operation. Note that the least significant bit is lost.

   PROCEDURE Main
      LOCAL cString := "AB"
      LOCAL cShift
      LOCAL nAsc1, nAsc2

      ? nAsc1 := Asc( cString[1] )      // result: 65
      ? nAsc2 := Asc( cString[2] )      // result: 66

      ? NtoC( nAsc1, 2, 8, "0" )        // result: 01000001
      ? NtoC( nAsc2, 2, 8, "0" )        // result: 01000010

      cShift := CharSHR( cString, 2 )

      ? nAsc1 := Asc( cShift[1] )       // result: 16
      ? nAsc2 := Asc( cShift[2] )       // result: 16
      ? NtoC( nAsc1, 2, 8, "0" )        // result: 00010000
      ? NtoC( nAsc2, 2, 8, "0" )        // result: 00010000
   RETURN

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