endianness

Python method for storing list of bytes in network (big-endian) byte order to file (little-endian)

My present task is to dissect tcpdump data that includes P2P messages and I am having trouble with the piece data I acquire and write to a file on my x86 machine. My suspicion is I have a simple endian-ness issue with the bytes I write to to file. I have a list of bytes holding a piece of P2P video read and processed using python-pcapy...

Is the binary representation of native types guaranteed the same on all targets?

I"m planning to store my data in a binary format as a resource, read it into an int buffer and basically pass it straight down to a native C++ function, which might cast it to a struct/class and work with it. No pointers, obviously, just ints and floats. The question is - what kind of fixing up do I need to do? I suppose that I need to ...

Any static analysis tools that help detect CPU endian issues?

Hello, Our team has managed a code base on an embedded big endian CPU for many years (10+). We have generally not bothered to consider endian issues during this development and maintenance of this embedded code. Soon, we will be moving this code base from a big endian CPU to a little endian CPU. We are curious if anyone has experien...

How to convert an integer to variable length byte string?

I want to convert an integer (int or long) a big-endian byte string. The byte string has to be of variable length, so that only the minimum number of bytes are used (the total length length of the preceding data is known, so the variable length can be inferred). My current solution is import bitstring bitstring.BitString(hex=hex(456))...

Help with endianness?

Hey guys I learned about endianness and am still having difficulty understanding where things could go wrong. I was wondering what sort of things I should look for and how I should go about fixing it. I know I dont need to change anything for loading from text files and things like that but for example here is a snippet of my code for lo...

Does this code check for endianess ?

Hi I heard in little endian, the LSB is at starting address and in Big endian MSB is at starting address. SO I wrote my code like this. If not why ? void checkEndianess() { int i = 1; char c = (char)i; if(c) cout<<"Little Endian"<<endl; else cout<<"Big Endian"<<endl; } ...

why my value are divided by 2 with bit fields

I got some trouble with bitfields and endian stuff... I confused. I need to parse some data got from the network, the sent are in lil endian (im using boost::asio) Can you explain me this struct TEST { unsigned short _last : 1; unsigned short _ID : 6; unsigned short _LENGH : 9; }; struct TEST2 { unsigned short _LENGH:9 ; unsigne...

Big->little (little->big) endian conversion of std::vector of structs

How can I perform endian conversion on vector of structs? For example: struct TestStruct { int nSomeNumber; char sSomeString[512]; }; std::vector<TestStruct> vTestVector; I know how to swap int values, but how to swap a whole vector of custom structs? ...

Ints to Bytes: Endianess a Concern?

Do I have to worry about endianness in this case (integers MUST be 0-127): int a = 120; int b = 100; int c = 50; char theBytes[] = {a, b, c}; I think that, since each integer sits in its own byte, I don't have to worry about Endianess in passing the byte array between systems. This has also worked out empirically. Am I...

Problems with byte-reversing an integer

Godday all. Could someone please explain the logical difference in these two implementations of a byte-reversing function. Example 1: uint32_t byte_reverse_32(uint32_t num) { static union bytes { uint8_t b[4]; uint32_t n; } bytes; bytes.n = num; uint32_t ret = 0; ret |= bytes.b[0] << 24; ret |=...

OLE Excel, unable to read last row. Little/big endian issue?

Hello, I'm trying to read an Excel file using OLE. The issue is that when the Excel file is located in a Unix share, when I try to read from it, I'm not able to read last row (only the last). However, if I copy the file to Windows beforehand, then it is OK. I think it might be some issue related to big/little endian. Any help would ...

How to read integers from a file that are 24bit and little endian using Python?

Is there an easy way to read these integers in? I'd prefer a built in method, but I assume it is possible to do with some bit operations. Cheers edit I thought of another way to do it that is different to the ways below and in my opinion is clearer. It pads with zeros at the other end, then shifts the result. No if required because shif...

Oracle RMAN big-endian to little-endian

Hi All, I have an Oracle RMAN backup that was created on a Solaris SPARC box and is therefore in big-endian format. I wish to restore this backup to a Windows x86-64 based machine but have hit a roadblock due to the endianness issue. I have read on Wikipedia http://en.wikipedia.org/wiki/Endianness#Endianness_in_files_and_byte_swap that...

How can I reverse the byte order of an NSInteger or NSUInteger in objective-c

This is a somewhat of a follow up to this posting (http://stackoverflow.com/questions/2718712/how-to-convert-byte-value-into-int-in-objective-c) but with a different question so I felt I should ask in a separate thread. I am at the point where I have four consecutive bytes in memory that I have read in from a file. I'd like to store ...

Compile PostgreSQL with reverse endianness

My old iMac G5 died recently. I had a PostgreSQL instance running there, and I kept backups. But when I went to restore them in my newer Macbook Pro, I realized that I couldn't do the restore due to byte endianness differences. Is there any compile flags that I can pass to PostgreSQL's configure script to use a reversed endianness on In...

Detect Endianness with CMake

My library needs to read-in big-endian integers (4-bytes) and covert them to the endian order of the host for processing. While on *nix ntohl has worked a treat under Windows use of ntohl requires the use of Ws2_32.dll (Winsock). Such a dependency is one which I would rather eliminate. The simplest way to do this appears to be to writ...

Little-Endian Signed Integer

I know the WAV file format uses signed integers for 16-bit samples. It also stores them in little-endian order, meaning the lowest 8 bits come first, then the next, etc. Is the special sign bit on the first byte, or is the special sign bit always on the most significant bit (highest value)? Meaning: Which one is the sign bit in the WAV ...

How to write a 24 bit message after reading from a 4-byte integer on a big endian machine (C)?

I am constructing a message to send a 24-bit number over the network. For little endian machines, the code is (ptr is the pointer to the message buffer): *ptr++ = (num >> 16) & 0xFF; *ptr++ = (num >> 8) & 0xFF; *ptr++ = (num) & 0xFF; (So if num0, num1, num2 and num3 are the individual bytes making up num, the message would be e...

Building a 32bit float out of its 4 composite bytes [C++]

I'm trying to build a 32bit float out of its 4 composite bytes. Is there a better (or more portable) way to do this than with the following method? #include <iostream> typedef unsigned char uchar; float bytesToFloat(uchar b0, uchar b1, uchar b2, uchar b3) { float output; *((uchar*)(&output) + 3) = b0; *((uchar*)(&output) ...