473,586 Members | 2,652 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

blazedaces
284 Contributor
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 5028
JosAH
11,448 Recognized Expert MVP
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 Contributor
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 "machinefor mat" (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 Recognized Expert MVP
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
11613
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 stay with C and still be able to produce Java byte code for platform independent apps. Also, old programs (with some tweaking) could be...
1
1572
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, the columns come from the DATA CTE, so datatype are well known ? Secondly, you can create such SQL: WITH CTE AS (VALUES(1),(2)) SELECT * FROM...
22
3693
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 wintel compilers support a 16-byte "long double" (with 33 decimal digits of accuracy) including proper printf() support. I found some compilers that...
3
14484
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 program (UNIX) as an array of "struct point" where struct point //C structure { int Time; //32 bits
32
4118
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 Source" manner, and in an attempt to build a ground-swell of support to convince the folks at Microsoft to add it. Proposal: "first:" "last:"...
5
4412
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 way to convert these to straight C#-compatible straight " byte" arrays? PS: The C++ DLL is actually managed and I have access to the source....
0
7912
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8202
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7959
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8216
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5710
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5390
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3837
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3865
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.