473,383 Members | 1,891 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,383 software developers and data experts.

Simple question: Why does Java write bytecode "high byte first"

blazedaces
284 100+
I was working all day yesterday (and will probably be for most of today) with bytecode where java wrote the bytecode and matlab read it... I had never worked with bytecode in great detail before so this was quite a challenge. I mean, all in all, the experience was interesting and because it was harder then it should have been, more educational.

Still, I've been told almost every other program reads "low byte first" and thinking about it, people usually when writing in byte-code write "low byte first". I don't know if it's true, but either way, is there a specific reason sun decided to read/write byte-code this way? Perhaps for encryption?

For those unfamiliar with byte-code, let's look at an example: if your number is let's say 3 and it's two bytes long (we'll say signed since we're talking java here) then it would be written (what I think is normal, "low byte first") simply like this:

Expand|Select|Wrap|Line Numbers
  1. 00000000 00000011
  2.  [byte 1]    [byte 2]
  3.  
But java would write it:
Expand|Select|Wrap|Line Numbers
  1. 00000011 00000000 
  2.  [byte 1]    [byte 2]
  3.  
Just curious. If the answer is simply, "because it does, why are apples red?" then so be it, I just want to know.

Thank you,

-blazed
Jul 27 '07 #1
3 5012
JosAH
11,448 Expert 8TB
High byte first, or 'big endian' is the international agreed way to transport them
over network wires etc. It's only Intel and a few others that use low byte first,
or 'little endian'. The Java virtual machine was a bit inspired by Sun's SPARC
processor which also uses big endian. When the byte code gets in the claws of
the JIT compiler (that turns the whole shebang into native machine code), the
big endian numbers as swapped around to little endian numbers.

kind regards,

Jos
Jul 27 '07 #2
blazedaces
284 100+
High byte first, or 'big endian' is the international agreed way to transport them
over network wires etc. It's only Intel and a few others that use low byte first,
or 'little endian'. The Java virtual machine was a bit inspired by Sun's SPARC
processor which also uses big endian. When the byte code gets in the claws of
the JIT compiler (that turns the whole shebang into native machine code), the
big endian numbers as swapped around to little endian numbers.

kind regards,

Jos
Very interesting. I had never known what 'big endian' or 'little endian' meant, but the words continued to pop up as I was trying to find the answer to my problem. I kept assuming that my long,int,short,double, etc. to unsigned byte converters were working incorrectly. Further testing brought me to the right conclusion.

This makes sense though, but now I'm wondering why Matlab is on default, that is if you don't specify the "machineformat" (it calls the option for big/little endian, etc.), little endian read format. I would suggest that the program that reads/writes all these files through matlab change it, but it's too highly used, I doubt they (my employers) would consider it, I'm just a lowly co-op.

Thank you again for the helpful information,

-blazed

Edit: I read further in the help section and found that it does the following by default: "Numeric format of the machine on which MATLAB is running (the default)" - what it calls 'Native' or for short 'n'.
Jul 27 '07 #3
JosAH
11,448 Expert 8TB
The term was first coined by Jonathan Swift in one of his Gulliver's Travels stories
where two tribes were in a severe fight about which side of a boiled egg should
be opened to eat it: the big endian side or the little endian side.

Of course those good old Vaxes had a 'from the middle' format as well.

kind regards,

Jos ;-)
Jul 27 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

235
by: napi | last post by:
I think you would agree with me that a C compiler that directly produces Java Byte Code to be run on any JVM is something that is missing to software programmers so far. With such a tool one could...
1
by: Jean-Marc Blaise | last post by:
Hi Serge, I have a question on your exciting recent article on High Perf. SQL: why do we have to describe datatype for include columns in an INSERT .... INCLUDE .... statement - in your example,...
22
by: bq | last post by:
Hello, Two questions related to floating point support: What C compilers for the wintel (MS Windows + x86) platform are C99 compliant as far as <math.h> and <tgmath.h> are concerned? What...
3
by: Pablo Gutierrez | last post by:
I have a C# method that reads Binary data (BLOB type) from a database and returns the data an array of bytes (i.e byte outbyte = new byte;). The BLOB column is saved into the database by a C...
32
by: James Curran | last post by:
I'd like to make the following proposal for a new feature for the C# language. I have no connection with the C# team at Microsoft. I'm posting it here to gather input to refine it, in an "open...
5
by: _BNC | last post by:
I've converted " byte" to "byte *" at times, using 'unsafe' and fixed { .... }, but the reverse does not seem to work. In this case, a C++ DLL returns a byte * and a length. What is the best...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...

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.