Re: Bitwise OR and AND without bitwise operators....



CelticDaddio wrote:
I am working in a programming language (GLSL) which does not support
bitwise operators, but I need to perform the following types of
calculations:

float b = (float)((counts & maskb) >> offsetg) / gbitres;

I can do the bit shifts by

Bit Shift Right ... i >> N = i / 2^N,
Bit Shift Left... i << N = i * 2^N,

right, but how can I do the bitwise AND? or a bitwise OR?

the lsb of n would be n-((n/2)*2).
the 2nd lsb of n would be m = n/2; m-((m/2)*2)
etc.
Notice you can re-use some results if you work lsb to msb.
So just iterate bitwise yourself and add 2^k to your result when the
bitwise operation on the kth bit is 1.

I don't know if this is the fastest way, but without bitwise arithmetic
support (which is why I assume bitwise operations are reserved), I
would think any solution would have to iterate over the operand's bits.

.



Relevant Pages

  • Re: Check for multiple file attributes
    ... are bitwise operators, meant to be used on integral types for bit ... Nicholas Paldino ... >> Yes, the FileAttributes enumeration is a bitwise mask, so you would>> compare in that manner. ... However, you do have to make sure the result is>> not zero, because C# does not assume that a non zero integer value>> evaluates to true, rather, you have to use a boolean value. ...
    (microsoft.public.dotnet.languages.csharp)
  • RE: Bitwise Comparison in WHERE Clause
    ... bitwise operators are provided by T-SQL. ... operators are used on int, smallint, or tinyint data. ...
    (microsoft.public.data.ado)
  • Re: program logic based on endianness
    ... The logic of shifting and action based on the result, ... assumes that the system is big-endian. ... I wanted to know if the above holds true for bitwise and and ... the bitwise operators -- work on the values of their ...
    (comp.unix.programmer)
  • Bitwise OR and AND without bitwise operators....
    ... I am working in a programming language which does not support ... but how can I do the bitwise AND? ...
    (sci.math)