How to figure out the byteorder only with one byte number?

Tao Jiang jiangtao.jit at gmail.com
Wed Feb 22 06:27:17 EST 2012


Hi:

Thank you all very much.


2012/2/21 Bernd Petrovitsch <bernd at petrovitsch.priv.at>:
> On Die, 2012-02-21 at 20:30 +0800, Tao Jiang wrote:
> [...]
>> Now I know in the most modern machine there is no difference between BE and LE
>> at so called 'bit order' level.
>> Right?
>
> One main difference between *byte* order and *bit* order is:
>
> What are the means to address individual *bits*?
> a) Bit shift and masking as in "1 << bit-number":
>   This has a mathematical background and - implicitly - the
>   least-significant bit has - thus - the number 0.
>   I can't even think of an insane reason (let alone a sane one) to
>   break the "shift left is for unsigned numbers equivalent to
>   doubling" property - apart from the fact that it is defined in that
>   way by C - and all other languages I came across. And the same holds
>   for all CPUs/assembler instruction sets ....
> b) use a bit-field as in "unsigned char b0:1, b1:1, b2:1, b3:1, b4:1,
>   b5:1, b6:1, b7:1;":
>   It is not defined by any C-standard and is - thus - up to the
>   compiler, if b0 == (1 << 0) or b0 == (1 << 7) or anything else.
> c) bit-test/st/clr assembler instructions in the architecture: Go read
>   *if* your CPU has such stuff and how it relates to the "bit-shift and
>   mask" method.
>   I would be greatly surprised if it is different (on i386, it is equal
>   since ages BTW) mainly because it makes absolutely no sense.
> d) There is hardware with bit-addressable memory out there. Go read the
>   manual and the same as c)
> I doubt that it is different even for really old machines ....
>
>        Bernd
> --
> Bernd Petrovitsch                  Email : bernd at petrovitsch.priv.at
>                     LUGA : http://www.luga.at
>



More information about the Kernelnewbies mailing list