xHarbour Reference Documentation > Function Reference |
Shifts bits in a character string to the left.
CharSHL( <cString>, <nShift> ) --> cResult
The function returns a string by shifting the bits of the individual characters of <cString> for <nShift> places to the left. The highest bit is discarded and the lowest bit is set to zero.
See also: | <<, CharAND(), CharNOT(), CharOR(), CharRLL(), CharRLR(), CharSHR(), CharXOR(), HB_BitShift() |
Category: | CT:String manipulation , Bitwise functions , Character functions , xHarbour extensions |
Source: | ct\charop.c |
LIB: | xhb.lib |
DLL: | xhbdll.dll |
// 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 left shift // operation. Note that the most 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 := CharSHL( cString, 2 ) ? nAsc1 := Asc( cShift[1] ) // result: 4 ? nAsc2 := Asc( cShift[2] ) // result: 8 ? NtoC( nAsc1, 2, 8, "0" ) // result: 00000100 ? NtoC( nAsc2, 2, 8, "0" ) // result: 00001000 RETURN
http://www.xHarbour.com