endianness

Why are both little- and big-endian in use?

佐手、 提交于 2019-11-28 17:46:21
Why are both little- and big-endian still in use today , after ~40 years of binary computer-science? Are there algorithms or storage formats that work better with one and much worse with the other? Wouldn't it be better if we all switched to one and stick with it? When adding two numbers (on paper or in a machine), you start with the least significant digits and work towards the most significant digits. (Same goes for many other operations). On the Intel 8088, which had 16-bit registers but an 8-bit data bus, being little-endian allowed such instructions to start operation after the first

Can endianness refer to bits order in a byte?

你离开我真会死。 提交于 2019-11-28 17:15:17
I'm reading "Learning Core Audio: A Hands-On Guide to Audio Programming for Mac and iOS" by Chris Adamson and at one point the author describes big-endian as: the high bits of a byte or word are numerically more significant than the lower ones. However, until now I though the problem of big-little endian only applies to byte order and not bit order. One byte has the same bit order (left to right) no matter if we're talking about little endian or big endian systems. Am I wrong? Is the author wrong? Or did I misunderstood his point? Since you can't normally address the bits within a byte

ASCII strings and endianness

我与影子孤独终老i 提交于 2019-11-28 15:58:57
An intern who works with me showed me an exam he had taken in computer science about endianness issues. There was a question that showed an ASCII string "My-Pizza", and the student had to show how that string would be represented in memory on a little endian computer. Of course, this sounds like a trick question because ASCII strings are not affected by endian issues. But shockingly, the intern claims his professor insists that the string would be represented as: P-yM azzi I know this can't be right. There is no way an ASCII string would be represented like that on any machine. But apparently,

When does Endianness become a factor?

我只是一个虾纸丫 提交于 2019-11-28 15:51:59
Endianness from what I understand, is when the bytes that compose a multibyte word differ in their order, at least in the most typical case. So that an 16-bit integer may be stored as either 0xHHLL or 0xLLHH . Assuming I don't have that wrong, what I would like to know is when does Endianness become a major factor when sending information between two computers where the Endian may or may not be different. If I transmit a short integer of 1, in the form of a char array and with no correction, is it received and interpretted as 256? If I decompose and recompose the short integer using the

Java : DataInputStream replacement for endianness

五迷三道 提交于 2019-11-28 10:04:43
Below is my code that replaces the DataInputStream to wrap an InputStream, but provides extra methods to read little endian data types in addition to the normal methods that read big endian types. Feel free to use it if you'd like. I have a few reservations as follows. Notice the methods that do not change functionality (the functions that read big endian types). There is no way I could implement the DataInputStream as the base class and use its methods, like read(), readInt(), readChar(), etc? My class hierarchy seems a little odd here. Is this appropriate? Do any of these other types like

Converting byte array values in little endian order to short values

六月ゝ 毕业季﹏ 提交于 2019-11-28 09:42:36
I have a byte array where the data in the array is actually short data. The bytes are ordered in little endian: 3, 1, -48, 0, -15, 0, 36, 1 Which when converted to short values results in: 259, 208, 241, 292 Is there a simple way in Java to convert the byte values to their corresponding short values? I can write a loop that just takes every high byte and shift it by 8 bits and OR it with its low byte, but that has a performance hit. With java.nio.ByteBuffer you may specify the endianness you want: order() . ByteBuffer have methods to extract data as byte, char, getShort() , getInt() , long,

C++ Byte order in socket programming

别说谁变了你拦得住时间么 提交于 2019-11-28 09:14:42
问题 In C++ we send data using socket on the network. I am aware that we need to use htons() , ntohs() function to maintain byte order big endian and little endian . support we have following data to be sent int roll; int id; char name[100]; This can also be wrapped into struct. My confusion here is, for roll and id , we can use htons() function. But for the string name , what should and how should we do it? Do we need to use any such function? will it work on every machine like mac, intel and

Endianness conversion in ARM

时光总嘲笑我的痴心妄想 提交于 2019-11-28 09:07:53
How do I convert big endian to little endian in ARM? old_timer Are you talking about ARM's endian modes, or reading something written by some other big endian processor, etc? Normally converting to/from big/little endian you swap the bytes around. So 0xABCD is 0xCDAB when viewed as a 16 bit number 0x12345678 is 0x78563412 when viewed as a 32 bit number. ARM cores armv5 and older (ARM7, ARM9, etc) have an endian mode known as BE-32, meaning big endian word invariant. armv6 and newer (mpcore, cortex-somethings) have BE-8, or big endian byte invariant. So if you are using an armv4 for example in

Signed right shift = strange result?

独自空忆成欢 提交于 2019-11-28 08:36:08
问题 I was helping someone with their homework and ran into this strange issue. The problem is to write a function that reverses the order of bytes of a signed integer(That's how the function was specified anyway), and this is the solution I came up with: int reverse(int x) { int reversed = 0; reversed = (x & (0xFF << 24)) >> 24; reversed |= (x & (0xFF << 16)) >> 8; reversed |= (x & (0xFF << 8)) << 8; reversed |= (x & 0xFF) << 24; return reversed; } If you pass 0xFF000000 to this function, the

Reading “integer” size bytes from a char* array.

青春壹個敷衍的年華 提交于 2019-11-28 07:38:16
I want to read sizeof(int) bytes from a char* array. a) In what scenario's do we need to worry if endianness needs to be checked? b) How would you read the first 4 bytes either taking endianness into consideration or not. EDIT : The sizeof(int) bytes that I have read needs to be compared with an integer value. What is the best approach to go about this problem Do you mean something like that?: char* a; int i; memcpy(&i, a, sizeof(i)); You only have to worry about endianess if the source of the data is from a different platform, like a device. a) You only need to worry about "endianness" (i.e.,