endianness

In Java, when writing to a file with DataOutputStream, how do I define the Endian of the data being written?

偶尔善良 提交于 2019-12-01 17:10:08
I'm using DataOutputStream to write to a file, however I want to change the endian of the data. This is how i'm writing the byte data to the file (it outputs in Little endian by default) public void generateBinObjFile(String outputFile) try { // Create file DataOutputStream stream = new DataOutputStream( new FileOutputStream(outputFile)); stream.writeShort(this.quantize(this.xComponents.get(index), //<-- Short is written in little Endian this.min_x, this.max_x) - 32768); } // catch statements here Is there a way i can define the Endian of how byte data is written in Java? You can not do this

which CPUs support MOVBE instruction?

不羁的心 提交于 2019-12-01 15:28:19
Sometimes GCC generates this instruction when compiling with -march=atom . Does each and every Intel Atom CPU support MOVBE? What other processors support this instruction? I can't seem to find this information on Intel website. Please help. GJ. This instruction was originally unique to the Intel® Atom™ processor. From Intel side: The Intel® Compilers 11.0 allow you to target the Intel® Atom™ processor using the /QxSSE3_ATOM or -xSSE3_ATOM compiler options. These options enable the generation of the movbe instruction which is unique to the Intel® Atom™ processor. In other microarchitectures (

which CPUs support MOVBE instruction?

我的未来我决定 提交于 2019-12-01 14:29:29
问题 Sometimes GCC generates this instruction when compiling with -march=atom . Does each and every Intel Atom CPU support MOVBE? What other processors support this instruction? I can't seem to find this information on Intel website. Please help. 回答1: This instruction was originally unique to the Intel® Atom™ processor. From Intel side: The Intel® Compilers 11.0 allow you to target the Intel® Atom™ processor using the /QxSSE3_ATOM or -xSSE3_ATOM compiler options. These options enable the

Endianness Work-around Needed

元气小坏坏 提交于 2019-12-01 12:26:46
问题 Consider the following piece of code: #include "stdio.h" typedef struct CustomStruct { short Element1[10]; }CustomStruct; void F2(char* Y) { *Y=0x00; Y++; *Y=0x1F; } void F1(CustomStruct* X) { F2((char *)X); printf("s = %x\n", (*X).Element1[0]); } int main(void) { CustomStruct s; F1(&s); return 0; } At run-time, by the end of calling the function F1 , I get different results by using different compilers. (*X).Element1[0] = 0x1f00 in some compiler and (*X).Element1[0] = 0x001f with another one

What is the C Equivalent of Python's pack(“<I”, 0)

笑着哭i 提交于 2019-12-01 11:17:48
I don't know much python but from what I can tell from the documentation the code: str = "AAAA" str += pack("<I", 0) would append the result of the pack function to str, which would be the integer value of 0 in little-endian style. My question is what the C equivalent of this would be. Would it just be: char str[20] = "AAAA"; strcat(str, "\x00"); ?... strcat() stops at the first NUL, so no. char str[20] = "AAAA"; int val = 0; int nval = htole32(val); memcpy(str + 4, (char*)&nval, 4); 来源: https://stackoverflow.com/questions/10771070/what-is-the-c-equivalent-of-pythons-packi-0

Simple bitwise manipulation for little-endian integer, in big-endian machine?

本小妞迷上赌 提交于 2019-12-01 07:04:17
For a specific need I am building a four byte integer out of four one byte chars, using nothing too special (on my little endian platform): return (( v1 << 24) | (v2 << 16) | (v3 << 8) | v4); I am aware that an integer stored in a big endian machine would look like AB BC CD DE instead of DE CD BC AB of little endianness, although would it affect the my operation completely in that I will be shifting incorrectly, or will it just cause a correct result that is stored in reverse and needs to be reversed? I was wondering whether to create a second version of this function to do (yet unknown) bit

Little Endian - Big Endian Problem

江枫思渺然 提交于 2019-12-01 06:49:42
Little Endian vs Big Endian Big Endian = 0x31014950 Little Endian = 0x50490131 However Using this Method inline unsigned int endian_swap(unsigned int& x) { return ( ( (x & 0x000000FF) << 24 ) | ( (x & 0x0000FF00) << 8 ) | ( (x & 0x00FF0000) >> 8 ) | ( (x & 0xFF000000) >> 24 ) ); } result = 0x54110131 i spent lot of time trying lots of similar methods and even a library one like unsigned long _byteswap_ulong(unsigned long value); But Still no luck .. all returns same result EDIT I'm Working on Little-Endian System with Microsoft Visual Studio 2008 the example as Follows int main() { unsigned

Any way to read big endian data with little endian program?

北城以北 提交于 2019-12-01 06:47:15
An external group provides me with a file written on a Big Endian machine, and they also provide a C++ parser for the file format. I only can run the parser on a little endian machine - is there any way to read the file using their parser without add a swapbytes() call after each read? Back in the early Iron Age, the Ancients encountered this issue when they tried to network primitive PDP-11 minicomputers with other primitive computers. The PDP-11 was the first little-Endian computer, while most others at the time were big-Endian. To solve the problem, once and for all, they developed the

how to get endianess in Java or python?

无人久伴 提交于 2019-12-01 06:16:29
问题 In C I could the Endianess of the machine by the following method. how would I get using a python or Java program?. In Java, char is 2-bytes unlike C where it is 1-byte . I think it might not be possible with python since it is a dynamic language , but I could be wrong bool isLittleEndian() { // 16 bit value, represented as 0x0100 on Intel, and 0x0001 else short pattern = 0x0001; // access first byte, will be 1 on Intel, and 0 else return *(char*) &pattern == 0x01; } 回答1: In Java, it's just

Calculator to convert binary to float value — what am I doing wrong?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-01 05:16:10
I have the following code, which writes 6 floats to disk in binary form and reads them back: #include <iostream> #include <cstdio> int main() { int numSegs = 2; int numVars = 3; float * data = new float[numSegs * numVars]; for (int i = 0; i < numVars * numSegs; ++i) { data[i] = i * .23; std::cout << data[i] << std::endl; } FILE * handle = std::fopen("./sandbox.out", "wb"); long elementsWritten = std::fwrite(data, sizeof(float), numVars*numSegs, handle); if (elementsWritten != numVars*numSegs){ std::cout << "Error" << std::endl; } fclose(handle); handle = fopen("./sandbox.out", "rb"); float *