I have a friend going to purdue university right now, and he was asked to write a program that determines which integer is larger, without using any conditional/control statements i.e. if, switch, etc, ?: operators, boolean logic operators or >= == or < etc. operators.
What I did was I wrote a program that masks the sign bit and returns it, i.e.: return ( x & 0xF0000000 ) >> 31;
and every time I use bit shift operators I start thinking about CPU endianness.
See I think little endian is retarded, and I prefer other architectures such as ARM and PPC to intel, but the way that they process and store data is different.
So Here's my question:
If I use a directional bitshift operator i.e. >> or <<, is the direction compensated for by your compiler/are these operators declared in terms of small versus big value bit, or do you need to switch the direction on a per-architecture basis?
Endianness and Bitwise Operators
-
- Gremlin
- Posts: 154
- Joined: Fri Jun 24, 2011 3:50 am
- Location: 192.168.0.1
- x 3
Endianness and Bitwise Operators
Sass not tolerated
LAY DOWN THE LAW!
When I don't understand a problem, I punch it in the face and try again.
LAY DOWN THE LAW!
When I don't understand a problem, I punch it in the face and try again.
-
- OGRE Expert User
- Posts: 1920
- Joined: Sun Feb 19, 2012 9:24 pm
- Location: Russia
- x 201
Re: Endianness and Bitwise Operators
The shift operators are defined in terms of "left" and "right" and have nothing to do with endianness unless you have a not retarted architecture with Arabic/Hebrew bit order 

-
- Gremlin
- Posts: 154
- Joined: Fri Jun 24, 2011 3:50 am
- Location: 192.168.0.1
- x 3
Re: Endianness and Bitwise Operators
I wasn't sure; because in Big endian systems like PPC and ARM, the big bits come first; so logically I'd think that the leftmost bit would be the largest, and on retarded architectures like intel
the smallest comes first (i.e. leftmost) so I though possibly that would affect leftmost versus rightmost.

Sass not tolerated
LAY DOWN THE LAW!
When I don't understand a problem, I punch it in the face and try again.
LAY DOWN THE LAW!
When I don't understand a problem, I punch it in the face and try again.
-
- OGRE Expert User
- Posts: 1227
- Joined: Thu Dec 11, 2008 7:56 pm
- Location: Bristol, UK
- x 157
Re: Endianness and Bitwise Operators
Also remember endianness, atleast in this context, is not the order of bits but the order of bytes, as it refers to how addresses are applied to bytes in memory for a particular data type (eg int). Bits dont have addresses, at least not on any architecture that I have worked with.
-
- Gnome
- Posts: 393
- Joined: Thu Dec 08, 2005 9:57 pm
- x 1
Re: Endianness and Bitwise Operators
While the site does not seem to contain the problem mentioned I suppose it does not hurt to mention it: http://graphics.stanford.edu/~seander/bithacks.html