How to figure out the byteorder only with one byte number?
Hi: As far as I know, we can use an integer 0x12345678 with four bytes and bytes[4] array to figure out a machine's byteorder Is there a method use only one byte 0x01 and some shifts do the same work? Thank you. --------------- jiangtao
I found: http://stackoverflow.com/questions/2100331/c-macro-definition-to-determine-b... On Sat, Feb 18, 2012 at 12:33 PM, Tao Jiang <jiangtao.jit@gmail.com> wrote:
Hi:
As far as I know, we can use an integer 0x12345678 with four bytes and bytes[4] array to figure out a machine's byteorder
Is there a method use only one byte 0x01 and some shifts do the same work?
Thank you.
--------------- jiangtao
_______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
-- Peter Senna Tschudin peter.senna@gmail.com gpg id: 48274C36
Peter: Thank you very much! I've read the url. But it's not what i mean to ask for. Those methods all use an int or a short number and converting. What I really want to ask for is: unsigned char byte = 0b00000100; do some shifts like byte << 1 then find out the machine's byteorder Is there some difference of the storge between BE and LE machine inside a byte? Thank you. 2012/2/18 Peter Senna Tschudin <peter.senna@gmail.com>:
I found:
http://stackoverflow.com/questions/2100331/c-macro-definition-to-determine-b...
On Sat, Feb 18, 2012 at 12:33 PM, Tao Jiang <jiangtao.jit@gmail.com> wrote:
Hi:
As far as I know, we can use an integer 0x12345678 with four bytes and bytes[4] array to figure out a machine's byteorder
Is there a method use only one byte 0x01 and some shifts do the same work?
Thank you.
--------------- jiangtao
_______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
-- Peter Senna Tschudin peter.senna@gmail.com gpg id: 48274C36
On Sun, 2012-02-19 at 20:08 +0800, Tao Jiang wrote: [...]
Is there some difference of the storge between BE and LE machine inside a byte?
No. At least TTBOMK there exists no such hardware. Bernd -- Bernd Petrovitsch Email : bernd@petrovitsch.priv.at LUGA : http://www.luga.at
On 02/20/2012 01:24 AM, Bernd Petrovitsch wrote:
On Sun, 2012-02-19 at 20:08 +0800, Tao Jiang wrote: [...]
Is there some difference of the storge between BE and LE machine inside a byte?
No. At least TTBOMK there exists no such hardware.
Using SHL/SHR would tell you - SHL normally results in a multiply by 2, SHR a divide by 2. If the byte was little endian, the results would be visa-versa But I agree, I doubt there is any such hardware Regards, Graeme
Hi: Thank you all. Take a byte number 0b00000001 for example ^ ^ high bit low bit I used to think in a LE machine it will be stored as 0b10000000 low bit first ^ ^ low bit high bit and in a BE machine will be 0b00000001 high bit first ^ ^ high bit low bit not only the byteorder is different, but inside a byte is also different. But actually they are the same, right? Thank you. 2012/2/20 Graeme Russ <graeme.russ@gmail.com>:
On 02/20/2012 01:24 AM, Bernd Petrovitsch wrote:
On Sun, 2012-02-19 at 20:08 +0800, Tao Jiang wrote: [...]
Is there some difference of the storge between BE and LE machine inside a byte?
No. At least TTBOMK there exists no such hardware.
Using SHL/SHR would tell you - SHL normally results in a multiply by 2, SHR a divide by 2. If the byte was little endian, the results would be visa-versa
But I agree, I doubt there is any such hardware
Regards,
Graeme
Hi Tao, On Mon, Feb 20, 2012 at 5:25 AM, Tao Jiang <jiangtao.jit@gmail.com> wrote:
Hi:
Thank you all.
Take a byte number 0b00000001 for example ^ ^ high bit low bit
I used to think in a LE machine it will be stored as 0b10000000 low bit first
^ ^
low bit high bit
and in a BE machine will be 0b00000001 high bit first ^ ^ high bit low bit
not only the byteorder is different, but inside a byte is also different.
But actually they are the same, right? yes they are same. In fact it is termed as 'byte' order not 'bit' order. Hope this helps. Thank you.
2012/2/20 Graeme Russ <graeme.russ@gmail.com>:
On 02/20/2012 01:24 AM, Bernd Petrovitsch wrote:
On Sun, 2012-02-19 at 20:08 +0800, Tao Jiang wrote: [...]
Is there some difference of the storge between BE and LE machine inside a byte?
No. At least TTBOMK there exists no such hardware.
Using SHL/SHR would tell you - SHL normally results in a multiply by 2, SHR a divide by 2. If the byte was little endian, the results would be visa-versa
But I agree, I doubt there is any such hardware
Regards,
Graeme
_______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Just as an FYI, way back in the early '90s, Texas Instruments came out with a graphics processor (I believe the TMS340x0 praphics processor) that actually did do the little-ending and big-endian down to the bit level. ________________________________ From: Subramaniam Appadodharana <c.a.subramaniam@gmail.com> To: Tao Jiang <jiangtao.jit@gmail.com> Cc: Graeme Russ <graeme.russ@gmail.com>; Bernd Petrovitsch <bernd@petrovitsch.priv.at>; Peter Senna Tschudin <peter.senna@gmail.com>; kernelnewbies@kernelnewbies.org Sent: Monday, February 20, 2012 8:53:10 AM Subject: Re: How to figure out the byteorder only with one byte number? Hi Tao, On Mon, Feb 20, 2012 at 5:25 AM, Tao Jiang <jiangtao.jit@gmail.com> wrote:
Hi:
Thank you all.
Take a byte number 0b00000001 for example ^ ^ high bit low bit
I used to think in a LE machine it will be stored as 0b10000000 low bit first
^ ^
low bit high bit
and in a BE machine will be 0b00000001 high bit first ^ ^ high bit low bit
not only the byteorder is different, but inside a byte is also different.
But actually they are the same, right? yes they are same. In fact it is termed as 'byte' order not 'bit' order. Hope this helps. Thank you.
2012/2/20 Graeme Russ <graeme.russ@gmail.com>:
On 02/20/2012 01:24 AM, Bernd Petrovitsch wrote:
On Sun, 2012-02-19 at 20:08 +0800, Tao Jiang wrote: [...]
Is there some difference of the storge between BE and LE machine inside a byte?
No. At least TTBOMK there exists no such hardware.
Using SHL/SHR would tell you - SHL normally results in a multiply by 2, SHR a divide by 2. If the byte was little endian, the results would be visa-versa
But I agree, I doubt there is any such hardware
Regards,
Graeme
_______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
_______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Guys, I was late to the party. But this whole discussion throughs me off. When you say byte order, it applied when the width of data is more than a byte, lets say our width is 4 bytes, a typical word length. Now how is that there will be byte order on a byte width data. Are you talking about nibble order. When you talk byte order -- either little endian or big endian, we are talking how is our data should be interpreted. Depending on order we start reading data from left or right a byte at a time. So, I am confused on your discussions. Please clarify. Thanks, Sri. On Mon, Feb 20, 2012 at 5:32 PM, THAI NGUYEN <thai-n@rogers.com> wrote:
Just as an FYI, way back in the early '90s, Texas Instruments came out with a graphics processor (I believe the TMS340x0 praphics processor) that actually did do the little-ending and big-endian down to the bit level.
________________________________ From: Subramaniam Appadodharana <c.a.subramaniam@gmail.com> To: Tao Jiang <jiangtao.jit@gmail.com> Cc: Graeme Russ <graeme.russ@gmail.com>; Bernd Petrovitsch <bernd@petrovitsch.priv.at>; Peter Senna Tschudin <peter.senna@gmail.com>; kernelnewbies@kernelnewbies.org Sent: Monday, February 20, 2012 8:53:10 AM Subject: Re: How to figure out the byteorder only with one byte number?
Hi Tao,
On Mon, Feb 20, 2012 at 5:25 AM, Tao Jiang <jiangtao.jit@gmail.com> wrote:
Hi:
Thank you all.
Take a byte number 0b00000001 for example ^ ^ high bit low bit
I used to think in a LE machine it will be stored as 0b10000000 low bit first
^ ^
low bit high bit
and in a BE machine will be 0b00000001 high bit first ^ ^ high bit low bit
not only the byteorder is different, but inside a byte is also different.
But actually they are the same, right? yes they are same. In fact it is termed as 'byte' order not 'bit' order. Hope this helps. Thank you.
2012/2/20 Graeme Russ <graeme.russ@gmail.com>:
On 02/20/2012 01:24 AM, Bernd Petrovitsch wrote:
On Sun, 2012-02-19 at 20:08 +0800, Tao Jiang wrote: [...]
Is there some difference of the storge between BE and LE machine inside a byte?
No. At least TTBOMK there exists no such hardware.
Using SHL/SHR would tell you - SHL normally results in a multiply by 2, SHR a divide by 2. If the byte was little endian, the results would be visa-versa
But I agree, I doubt there is any such hardware
Regards,
Graeme
_______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
_______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
_______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
-- Regards, Sri.
Hi: I think I'm clear now. What's I originally wanted to ask for is whether 'bit order' equals to 'byte order' And is there a method to find out the 'bit order' then find out the 'byte order' ? Now I know in the most modern machine there is no difference between BE and LE at so called 'bit order' level. Right? Thank you all. 2012/2/21 Sri Ram Vemulpali <sri.ram.gmu06@gmail.com>:
Guys,
I was late to the party. But this whole discussion throughs me off. When you say byte order, it applied when the width of data is more than a byte, lets say our width is 4 bytes, a typical word length.
Now how is that there will be byte order on a byte width data. Are you talking about nibble order.
When you talk byte order -- either little endian or big endian, we are talking how is our data should be interpreted. Depending on order we start reading data from left or right a byte at a time.
So, I am confused on your discussions. Please clarify.
Thanks, Sri.
On Mon, Feb 20, 2012 at 5:32 PM, THAI NGUYEN <thai-n@rogers.com> wrote:
Just as an FYI, way back in the early '90s, Texas Instruments came out with a graphics processor (I believe the TMS340x0 praphics processor) that actually did do the little-ending and big-endian down to the bit level.
________________________________ From: Subramaniam Appadodharana <c.a.subramaniam@gmail.com> To: Tao Jiang <jiangtao.jit@gmail.com> Cc: Graeme Russ <graeme.russ@gmail.com>; Bernd Petrovitsch <bernd@petrovitsch.priv.at>; Peter Senna Tschudin <peter.senna@gmail.com>; kernelnewbies@kernelnewbies.org Sent: Monday, February 20, 2012 8:53:10 AM Subject: Re: How to figure out the byteorder only with one byte number?
Hi Tao,
On Mon, Feb 20, 2012 at 5:25 AM, Tao Jiang <jiangtao.jit@gmail.com> wrote:
Hi:
Thank you all.
Take a byte number 0b00000001 for example ^ ^ high bit low bit
I used to think in a LE machine it will be stored as 0b10000000 low bit first
^ ^
low bit high bit
and in a BE machine will be 0b00000001 high bit first ^ ^ high bit low bit
not only the byteorder is different, but inside a byte is also different.
But actually they are the same, right? yes they are same. In fact it is termed as 'byte' order not 'bit' order. Hope this helps. Thank you.
2012/2/20 Graeme Russ <graeme.russ@gmail.com>:
On 02/20/2012 01:24 AM, Bernd Petrovitsch wrote:
On Sun, 2012-02-19 at 20:08 +0800, Tao Jiang wrote: [...]
Is there some difference of the storge between BE and LE machine inside a byte?
No. At least TTBOMK there exists no such hardware.
Using SHL/SHR would tell you - SHL normally results in a multiply by 2, SHR a divide by 2. If the byte was little endian, the results would be visa-versa
But I agree, I doubt there is any such hardware
Regards,
Graeme
_______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
_______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
_______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
-- Regards, Sri.
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@petrovitsch.priv.at LUGA : http://www.luga.at
Hi: Thank you all very much. 2012/2/21 Bernd Petrovitsch <bernd@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@petrovitsch.priv.at LUGA : http://www.luga.at
participants (7)
-
Bernd Petrovitsch -
Graeme Russ -
Peter Senna Tschudin -
Sri Ram Vemulpali -
Subramaniam Appadodharana -
Tao Jiang -
THAI NGUYEN