Welcome! Log In Create A New Profile

Advanced

Shift for bits

Posted by Marco Rego.pcs.crosspost 
Marco Rego.pcs.crosspost
Shift for bits
August 27, 2008 05:24PM
Are there any shift left and right related functions for dealing with bits ?
Just found BinaryAND/OR/XOR and it is not exactly what I am looking for.

Message forwarded from pcsoft.us.windev
BLS.pcs.crosspost
Re: Shift for bits
August 27, 2008 05:50PM
Marco Rego schrieb:
> Are there any shift left and right related functions for dealing with bits ?
> Just found BinaryAND/OR/XOR and it is not exactly what I am looking for.
>

Hi Marco,
NO, it's a shame but WD has no (or pretty less) support for bit-wise
operations.

However code for shiftleft << and shiftright >> , enjoy.

PROCEDURE ShiftLeft(nInt, nBitsToShift)

nResult is int

WHEN EXCEPTION
ExceptionEnable()
RESULT -1
END

nResult = nInt * Power(2, nBitsToShift)

RESULT nResult

FUNCTION ShiftRight(nInt, nBitsToShift)

nRetval is int
WHEN EXCEPTION
// Capacity Error
ExceptionEnable()
RESULT -1
END

nRetval = nInt / Power(2, nBitsToShift)

RESULT nRetval

PS ..the lack of bit operations in WD is quit annoying. So I wrote all
"low level" code in the D programming language. a DLL then ...
(D is in fact C++ on steroids, without bee'ing too complicated)

[www.digitalmars.com]

HTH Bjoern
Message forwarded from pcsoft.us.windev
BLS
Re: Shift for bits
August 27, 2008 05:52PM
Marco Rego :
> Are there any shift left and right related functions for dealing with bits ?
> Just found BinaryAND/OR/XOR and it is not exactly what I am looking for.
>

Hi Marco,
NO, it's a shame but WD has no (or pretty less) support for bit-wise operations.

However code for shiftleft << and shiftright >> , enjoy.

PROCEDURE ShiftLeft(nInt, nBitsToShift)

    nResult is int
   
    WHEN EXCEPTION
        ExceptionEnable()
        RESULT -1
    END
   
    nResult = nInt * Power(2, nBitsToShift)
   
RESULT nResult

FUNCTION ShiftRight(nInt, nBitsToShift)

    nRetval is int
    WHEN EXCEPTION
        // Capacity Error
        ExceptionEnable()
        RESULT -1
    END

    nRetval = nInt / Power(2, nBitsToShift)

RESULT nRetval

PS ..the lack of bit operations in WD is quit annoying. So I wrote all "low level" code in the D programming language. [means create a DLL]
Beside ... can't resist :
(D is in fact C++ on steroids, without being too complicated, at least ...compared to C++ winking smiley )
[www.digitalmars.com]

HTH Bjoern

Author:

Your Email:


Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
Message: