473,406 Members | 2,956 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

endianness and 64-bit machines

When comparing strings, if a machine is big-endian, even if strings are
not aligned, you can do some shifts then do word comparisons rather
than byte-by-byte comparisons. Little-endian machines, though, haven't
much choice but to read strings byte by byte during comparisons. The
expense of those shifts is a little less than the cost of reading
things byte-by-byte on 32-bit machines. But on 64-bit machines, the
shift-and-compare-words approach is much faster than the byte-by-byte
approach.

So being big-endian has an advantage, and it's a bigger advantage for
64-bit machines than it is for 32-bit machines. How much does this
matter? I know databases spend a lot of time doing comparisons.

May 17 '06 #1
7 3758
bo*********@burtleburtle.net wrote:

When comparing strings, if a machine is big-endian,
even if strings are
not aligned, you can do some shifts then do word comparisons rather
than byte-by-byte comparisons.
Little-endian machines, though, haven't
much choice but to read strings byte by byte during comparisons. The
expense of those shifts is a little less than the cost of reading
things byte-by-byte on 32-bit machines. But on 64-bit machines, the
shift-and-compare-words approach is much faster than the byte-by-byte
approach.

So being big-endian has an advantage, and it's a bigger advantage for
64-bit machines than it is for 32-bit machines. How much does this
matter? I know databases spend a lot of time doing comparisons.


Followup to:
news:comp.programming

--
pete
May 17 '06 #2
>When comparing strings, if a machine is big-endian, even if strings are
not aligned, you can do some shifts then do word comparisons rather
than byte-by-byte comparisons. Little-endian machines, though, haven't
much choice but to read strings byte by byte during comparisons.
I don't believe this. If you can do it with big-endian, you can do
it with little-endian, until you find a mismatch, at which point
you need to deal with figuring out whether the mismatch is beyond the
string terminator or not (on big-endian, little-endian, and non-endian
machines).
The
expense of those shifts is a little less than the cost of reading
things byte-by-byte on 32-bit machines.
This sounds like an unwarranted generalization, probably from a single
64-bit machine.
But on 64-bit machines, the
shift-and-compare-words approach is much faster than the byte-by-byte
approach. So being big-endian has an advantage,
For a single very narrow purpose. Being big-endian also has a disadvantage
for multi-precision addition/subtraction.
and it's a bigger advantage for
64-bit machines than it is for 32-bit machines. How much does this
matter? I know databases spend a lot of time doing comparisons.


Gordon L. Burditt
May 17 '06 #3
Gordon Burditt wrote:
When comparing strings, if a machine is big-endian, even if
strings are not aligned, you can do some shifts then do word
comparisons rather than byte-by-byte comparisons. Little-endian
machines, though, haven't much choice but to read strings byte
by byte during comparisons.


I don't believe this. If you can do it with big-endian, you can
do it with little-endian, until you find a mismatch, at which
point you need to deal with figuring out whether the mismatch is
beyond the string terminator or not (on big-endian, little-endian,
and non-endian machines).


Please preserve attributions for material you quote.

Once more, the distribution of actual string sizes in a system
comes into play. I assume, without more justification than
instinct, that most strings are short, and thus the effort to
switch between comparision of large entities and single chars is
not going to be efficacious.

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
More details at: <http://cfaj.freeshell.org/google/>
Also see <http://www.safalra.com/special/googlegroupsreply/>
May 17 '06 #4
On Wed, 17 May 2006 -0000 (Gordon Burditt) wrote:
So being big-endian has an advantage,


For a single very narrow purpose. Being big-endian also has a disadvantage
for multi-precision addition/subtraction.


if little endian is something like
<----><---->
a[0] a[1]
i agree it is easier because the number can increase
<----><----><---->
a[0] a[1] a[2]

in big endian i have to move the pointer
<----><----><---->
a[-1] a[0] a[1]

so little endian is how represent number in a computer and
0d=0b, 1d=1b, 2d==01b, 3d==11b,4d=001b, 5d=101b, 6d=011b etc
and it's a bigger advantage for
64-bit machines than it is for 32-bit machines. How much does this
matter? I know databases spend a lot of time doing comparisons.


Gordon L. Burditt

May 19 '06 #5
"Gordon Burditt" <go***********@burditt.org> wrote
So being big-endian has an advantage,


For a single very narrow purpose. Being big-endian also has a
disadvantage
for multi-precision addition/subtraction.

But it has the big advantage that Microsoft don't use it.
After all, if we don't do everything we can to stop them, they might take
over the world and force us all to store our bytes at the little end.
--
www.personal.leeds.ac.uk/~bgy1mm


May 20 '06 #6
bo*********@burtleburtle.net wrote:
When comparing strings, if a machine is big-endian, even if strings are
not aligned, you can do some shifts then do word comparisons rather
than byte-by-byte comparisons. Little-endian machines, though, haven't
much choice but to read strings byte by byte during comparisons. The
expense of those shifts is a little less than the cost of reading
things byte-by-byte on 32-bit machines. But on 64-bit machines, the
shift-and-compare-words approach is much faster than the byte-by-byte
approach.

So being big-endian has an advantage, and it's a bigger advantage for
64-bit machines than it is for 32-bit machines. How much does this
matter? I know databases spend a lot of time doing comparisons.


Newbie question:

What does endianness mean? And what's a big-endian machine?
Best regards / Med venlig hilsen
Martin Jørgensen

--
---------------------------------------------------------------------------
Home of Martin Jørgensen - http://www.martinjoergensen.dk
May 20 '06 #7
Martin Jørgensen said:

<snip>
Newbie question:

What does endianness mean? And what's a big-endian machine?


http://www.catb.org/~esr/jargon/html/B/big-endian.html
http://www.catb.org/~esr/jargon/html...le-endian.html
http://www.catb.org/~esr/jargon/html...le-endian.html
http://www.catb.org/~esr/jargon/html...I-problem.html

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
May 20 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: pramod | last post by:
Two different platforms communicate over protocols which consist of functions and arguments in ascii form. System might be little endian/big endian. It is possible to format string using sprintf...
3
by: kelvSYC | last post by:
Are there any endianness concerns in C++, or does the compiler take care of those details? I ask because I'm not sure if code such as the following have consistent behavior on all platforms. ...
26
by: Case | last post by:
#include <string.h> int i; /* 4-byte == 4-char */ char data = { 0x78, 0x56, 0x34, 0x12 }; int main() { memcpy(&i, data, 4); /*
15
by: T Koster | last post by:
Hi group, I'm having some difficulty figuring out the most portable way to read 24 bits from a file. This is related to a Base-64 encoding. The file is opened in binary mode, and I'm using...
18
by: friend.05 | last post by:
Code to check endianness of machine
134
by: jacob navia | last post by:
Hi Suppose you have somewhere #define BOOL int and somewhere else typedef BOOL int;
18
by: Indian.croesus | last post by:
Hi, If I am right Endianness is CPU related. I do not know if the question is right in itself but if it is then how does C handle issues arising out of Endianness. I understand that if we pass...
5
by: Rahul | last post by:
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. ...
19
by: perry.yuan | last post by:
How could I determine the endianness of my compile environment at compile time, instead of run time? I need a macro ("some_expression"), i.e. #if some_expression #define TARGET_IS_LITTLE_ENDIAN...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.