On Mon, Sep 28, 2009 at 12:43 PM, Przemyslaw Czerpak <dru...@acn.waw.pl> wrote:
> Not tested, just written: > > func BIT( cValue, nOffset, lSet ) > local lResult, nChar > ... Many thanks. I'm not sure my test is correct but I'm still not getting the same results. best regards, Lorenzo Here is my test code: proc main local cTest := chr(63)+chr(255)+chr(63)+chr(255) ? bit(cTest,1),bitnew(cTest,1) ? bit(cTest,4),bitnew(cTest,4) ? bit(cTest,16),bitnew(cTest,16) ? bit(cTest,32),bitnew(cTest,32) return function bitnew( cValue, nOffset, lSet ) local lResult, nChar nChar := strpeek( cValue, nOffset / 8 ) lResult = hb_bitTest( nChar, nOffset % 8 ) if valtype( lSet ) == "L" .and. lSet != lResult strpoke( @cValue, nOffset / 8, ; iif( lSet, hb_bitSet( nChar, nOffset % 8 ), ; hb_bitReset( nChar, nOffset % 8 ) ) ) endif return lResult #pragma BEGINDUMP #include <extend.h> #ifdef __HARBOUR__ HB_FUNC( BIT ) #else CLIPPER bit( void ) #endif { char *ptr; unsigned char mask; unsigned int loc, offset = _parni( 2 ) - 1, res = 0; loc = offset / 8; if ( loc < _parclen( 1 ) ) { ptr = _parc( 1 ) + loc; loc = offset % 8; res = *ptr << loc & 0x80; if ( PCOUNT > 2 ) { mask = (unsigned char ) 0x80 >> loc; if ( _parl( 3 ) ) *ptr = *ptr | mask; else *ptr = *ptr & ~mask; } } _retl( res ); } #pragma ENDDUMP _______________________________________________ Harbour mailing list Harbour@harbour-project.org http://lists.harbour-project.org/mailman/listinfo/harbour