Re: program logic based on endianness



sam_cit@xxxxxxxxxxx wrote:
Hi Everyone,

I have a program unit which does >> and << of an integer which is of
4 bytes length. The logic of shifting and action based on the result,
assumes that the system is big-endian.

Accordingly, if i need the program to work fine in a little-endian
system. I understand that the code needs to be changed.

I wanted to know if the above holds true for bitwise and (&) and
bitwise or (|). I think, the processor should take care of the
operation a&b or a|b irrespective of the endianness of the system.

Please provide your comments.

Most C operators -- including the shift operators and
the bitwise operators -- work on the values of their
operands, not on the representations. `16 << 2' is always
64, never 4 (and never anything even weirder).

--
Eric Sosman
esosman@xxxxxxxxxxxxxxxxxxxx
.



Relevant Pages

  • 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 ... operation a&b or a|b irrespective of the endianness of the system. ...
    (comp.unix.programmer)
  • 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: Unicode chinese
    ... bitwise and bit shifting? ... Roedy Green Canadian Mind Products ...
    (comp.lang.java.programmer)
  • Re: Bitwise OR and AND without bitwise operators....
    ... but how can I do the bitwise AND? ... 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 ...
    (sci.math)