endianness

Swapping Endianness In Objective-C?

I need to swap the endianness of some values and just wondered if there was anything available in Objective-C, currently I am swapping the bytes with the CStyle function below (which obviously I can reuse) I just wanted to check there was nothing specific I was missing? float floatFlip(float inFloat) { union { int intValue; ...

how to pass xml schema through sockets ?

Hi Could someone please help and tell me if there is a possibility to pass an xml schema through a socket program written in C/C++ ? here is an example: ---- c/C++ ---- ... struct zone { // as an example char *Var_name="xxx"; float var_value = 1.3; }; ----- xml --- ... <xs:element name="zone"> <xs:complexType> <xs:sequence>...

What's a portable way of converting Byte-Order of strings in C

I am trying to write server that will communicate with any standard client that can make socket connections (e.g. telnet client) It started out as an echo server, which of course did not need to worry about network byte ordering. I am familiar with ntohs, ntohl, htons, htonl functions. These would be great by themselves if I were trans...

Reversing every character in a file

I'm in a little trouble here. Can anyone help me implement a solution that reverses every byte so 0xAB becomes 0xBA but not so "abcd" becomes "dcba". I need it so AB CD EF becomes BA DC FE. Preferably in C or C++ but it doesn't really matter provided it can run. So far, I've implemented a UBER CRAPPY solution that doesn't even work (a...

.net reversing byte order?

In the code below, why do X and Y take on different values than what I would think intuitively? If the bytes 0-7 are written to the buffer, shouldn't the resulting long have bytes in the same order? It's like it's reading the long values in reverse order. x 0x0706050403020100 long y 0x0706050403020100 long z 0x0001020304050607...

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

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? ...

Unexpected behavior when printing 4-byte integer byte by byte.

I have this sample code for converting 32 bit integers to ip addresses. #include <stdio.h> int main() { unsigned int c ; unsigned char* cptr = (unsigned char*) while(1) { scanf("%d", printf("Integer value: %u\n",c); printf("%u.%u.%u.%u \n",*cptr, *(cptr+1), *(cptr+2), *(cptr+3) ); } } This code gives incorrect output for...

Python equivalent for Ruby's pack function

Hi! I'm translating some of my old Ruby scripts into Python and I have trouble finding a function in Python that belongs to Ruby: http://www.ruby-doc.org/core/classes/Array.src/M002222.html - which keeps the array in little endian byte order. Is there any Python module that can help me? ...

C Macro definition to determine big endian or little endian machine ?

Is there a one line macro definition to determine the endianness of the machine. I am using the following code but converting it to macro would be too long. unsigned char test_endian( void ) { int test_var = 1; unsigned char test_endian* = (unsigned char*)&test_var; return (test_endian[0] == NULL); } ...

Big Endian and Little Endian for Files in C++

I am trying to write some processor independent code to write some files in big endian. I have a sample of code below and I can't understand why it doesn't work. All it is supposed to do is let byte store each byte of data one by one in big endian order. In my actual program I would then write the individual byte out to a file, so I get ...

convert big endian to little endian in C [without using provided func]

I need to write a function to convert big endian to little endian in C. I can not use any library function. ...

flip bytes using Python's struct module

I would like to flip from big to little endian this string: \x00\x40 to have it like this: \x40\x00 I guess the proper function to use would be struct.pack, but I can't find a way to make it properly work. A small help would be very appreciated ! Thanks ...

Getting 32 bit words out of 64-bit values in C/C++ and not worrying about endianness...

It's my understanding that in C/C++ bitwise operators are supposed to be endian independent and behave the way you expect. I want to make sure that I'm truly getting the most significant and least significant words out of a 64-bit value and not worry about endianness of the machine. Here's an example: uint64_t temp; uint32_t msw, lsw;...

Convert "little endian" hex string to IP address in Python

What's the best way to turn a string in this form into an IP address: "0200A8C0". The "octets" present in the string are in reverse order, i.e. the given example string should generate 192.168.0.2. ...

When to worry about endianness?

I have seen countless references about endianness and what it means. I got no problems about that... However, my coding project is a simple game to run on linux and windows, on standard "gamer" hardware. Do I need to worry about endianness in this case? When should I need to worry about it? My code is simple C and SDL+GL, the only compl...

Extracting the value represented by a particular set of bits in a number

How to extract the value represented by a particular set of bits in a given number i.e. if bits 11,12 & 13 are 1,1,0 then the value should be 6. What is the most efficient way of doing the same? Also, it should be generic. I should be able to give start and end bit positions and should be able to extract the value represented by the bit...

What is the name for a number which is the same in both big- and little-endian byte order?

One of my old classmates just asked me this and I'm at a total loss. Google gave me a lot of definitions of endian-ness, but not the term for this special case. IS there even a term for this? ...

Is C# Endian sensitive?

Is C# ever Endian sensitive, for example, will code such as this: int a = 1234567; short b = *(short*)&i; always assign the same value to b. If so, what value will it be? If not, what good ways are there to deal with endianness if code with pointers in? ...

How can I pack an int as 32 bits big endian in Perl?

Consider this snippet: use strict; use warnings; my $data = "1"; my $packed = pack("I",$data); open(my $file,">","test.bin") || die "error $!\n"; binmode $file; print $file $packed; The thing is, trying to read it from another language, this appears to be little endian. Is there any template argument that allows me to write it as big...

Swapping bytes in C (endianness)

I'm trying to swap bytes for an assignment, and I thought this would be the way to do it. p points to the scalar object to be reversed size is the number of bytes of the object. void *ReverseEndian(void *p, size_t size) { char *head = (char *)&p; char *tail = head + size - 1; for (; tail > head; --tail, ++head) { ...