endianness

Storing dword into address

久未见 提交于 2019-12-12 04:40:06
问题 I'm in middle of teaching myself certain parts of Assembly Language, and right now, I am focusing on storing data declarations in addresses. When it comes to storing hex, I know that if I am dealing with bytes, for instance; 1234 I can store them like this: Address 0000 - 12 Address 0001 - 24 Because dwords are 32 bits, I am assuming that each would take up twice as much space. If I end up with this for dword: 54 00 87 D1 49 5A AF 56 32 Would they be stored like this: Address 0000 - 54

byte flipping data in C++ returns only zeroes

爷,独闯天下 提交于 2019-12-12 04:04:56
问题 I'm using the GCC compiler (codeblocks) on windows, and the data I'm getting is from a UNIX machine, so it's all in big-endian. I have to swap it to little endian before I can us it. And I'll be dammed, but I can't get this to work. Using temp = ntohl(fileBuf[N*i+j]); or _byteswap_ulong(fileBuf[N*i+j]); returns nothing but zeroes. Which I know for a fact is incorrect. The incoming data is just a string of 32bit integers (elevation data for part of the USA). Any help is greatly appreciated

reading binary from a file gives negative number

南楼画角 提交于 2019-12-12 02:21:55
问题 Hey everyone this may turn out to be a simple stupid question, but one that has been giving me headaches for a while now. I'm reading data from a Named Binary Tag file, and the code is working except when I try to read big-endian numbers. The code that gets an integer looks like this: long NBTTypes::getInteger(istream &in, int num_bytes, bool isBigEndian) { long result = 0; char buff[8]; //get bytes readData(in, buff, num_bytes, isBigEndian); //convert to integer cout <<"Converting bytes to

How to swap 64 bit integer while extracting bytes from bytearray in C++?

梦想与她 提交于 2019-12-11 20:07:11
问题 I am tring to read couple of bytes from byteData as mentioned below in my C++ code. The actual value within byteData is a binary blob byte array in BIG-ENDIAN byte order format. So I cannot simply just "cast" the byte array into a String.. byteData byte array is composed of these three things - First is `schemaId` which is of two bytes (short datatype in Java) Second is `lastModifiedDate` which is of eight bytes (long datatype in Java) Third is the length of actual `byteArray` within

Fast way to swap endianness using opencl

末鹿安然 提交于 2019-12-11 19:44:53
问题 I'm reading and writing lots of FITS and DNG images which may contain data of an endianness different from my platform and/or opencl device. Currently I swap the byte order in the host's memory if necessary which is very slow and requires an extra step. Is there a fast way to pass a buffer of int/float/short having wrong endianess to an opencl-kernel? Using an extra kernel run just for fixing the endianess would be ok; using some overheadless auto-fixing-read/-write operation would be perfect

Why is the order of bit fields in the bytes of structs not defined by the language itself?

送分小仙女□ 提交于 2019-12-11 16:05:20
问题 I came across a problem today where I discovered the way the bit fields in my bytes are ordered is dependent on the endianness of my processor. Take the next example: struct S { uint8_t a : 3; uint8_t b : 5; }; This struct takes one byte but the bit layout depends on the machine: Little endian: b4 b3 b2 b1 b0 a2 a1 a0 Big endian: a2 a1 a0 b4 b3 b2 b1 So on a little endian machine it starts filling from the LSB and on a big endian machine it start filling from the MSB. I once heard Stroustrup

Endianness for floating point

折月煮酒 提交于 2019-12-11 10:21:50
问题 I'm writing and reading binary data ( std::ios::binary ) in C++ using std::fstream - this includes integer and floating point values. While my code works on my own architecture, I wan't to make sure, that it's portable and i.e. binary files written on my machine shall still be read properly of an machine with different endianness. So my idea was that I will add in the binary file at first byte a value which will indicate the endianness of the file. As there is no guarantee, that endianness of

Ruby how to convert 32 bit integer to network byte order? [duplicate]

别来无恙 提交于 2019-12-11 08:09:35
问题 This question already has an answer here : Closed 7 years ago . Possible Duplicate: How to convert 32 bit integer to network byte order? I already asked "How to convert 32 bit integer to network byte order?" but still I don't understand the concept. I need to write the length of the data to socket in network byte order. For example if the size of the data in bytes is 1024 then I need to express this as network byte order in Ruby. As per the answer for my earlier question it will be: [1,0,2,4]

How to deal with 'Endianness'

我们两清 提交于 2019-12-11 07:34:25
问题 I’m still working on a properly functioning ICMP listener and puzzling how to deal with ‘endianness’. My first approach was getting the data out of the buffer into an appropriate (array initially) field (uint etc.) and then reversing the byte order, before passing the data on to the appropriate BitConverter member. Though it works, it is not very elegant. Second approach was to prepare the entire buffer driven by a two dimensional array, containing the position and length of fields, that need