endianness

Command-line to reverse byte order/change endianess

ぐ巨炮叔叔 提交于 2019-12-04 00:29:34
I'm hacking around in some scripts trying to parse some data written by Javas DataOutputStream#writeLong(...) . Since java always seems to write big endian, I have a problem feeding the bytes to od . This is due to the fact that od always assumes that the endianess matches the endianess of the arch that you are currently on, and I'm on a little endian machine. I'm looking for an easy one-liner to reverse the byte order. Let's say that you know that the last 8 bytes of a file is a long written by the aforementioned writeLong(...) method. My current best attempt to print this long is tail -c 8

ByteBuffer Little Endian insert not working

我怕爱的太早我们不能终老 提交于 2019-12-03 22:27:31
I have to make a two way communication between a legacy system and an android device. The legacy system uses little endian byte ordering. I have successfully implemented the receiving part, however sending not works. Strange because for me it seems that the ByteBuffer class malfunctions (I can hardly believe that) ByteBuffer byteBuffer = ByteBuffer.allocate(4); byteBuffer.order(ByteOrder.LITTLE_ENDIAN); byteBuffer = ByteBuffer.allocate(4); byteBuffer.putInt(88); byte[] result = byteBuffer.array(); Results: [0, 0, 0, 88] ByteBuffer byteBuffer = ByteBuffer.allocate(4); byteBuffer.order(ByteOrder

How to transform phrases and words into MD5 hash?

隐身守侯 提交于 2019-12-03 21:41:38
Can anyone, please, explain to me how to transform a phrase like "I want to buy some milk" into MD5? I read Wikipedia article on MD5, but the explanation given there is beyond my comprehension: "MD5 processes a variable-length message into a fixed-length output of 128 bits. The input message is broken up into chunks of 512-bit blocks (sixteen 32-bit little endian integers)" "sixteen 32-bit little endian integers" is already hard for me. I checked the Wiki article on little endians and didn't understand a bit. However, the examples of some phrases and their MD5 hashes in that Wiki article are

how is data stored at bit level according to “Endianness”?

会有一股神秘感。 提交于 2019-12-03 21:23:21
I read about Endianness and understood squat... so I wrote this main() { int k = 0xA5B9BF9F; BYTE *b = (BYTE*)&k; //value at *b is 9f b++; //value at *b is BF b++; //value at *b is B9 b++; //value at *b is A5 } k was equal to A5 B9 BF 9F and (byte)pointer " walk " o/p was 9F BF b9 A5 so I get it bytes are stored backwards...ok. ~ so now I thought how is it stored at BIT level... I means is "9f"(1001 1111) stored as "f9"(1111 1001)? so I wrote this int _tmain(int argc, _TCHAR* argv[]) { int k = 0xA5B9BF9F; void *ptr = &k; bool temp= TRUE; cout<<"ready or not here I come \n"<<endl; for(int i=0;i

iPhone platform: endianness (detection & swapping)

半世苍凉 提交于 2019-12-03 20:31:04
I'm doing some endian-sensitive file manipulation on iPhone. Are there standard macros or #defines in that environment that indicate native endianness and offer swapping if necessary? I know I can check in advance and just do the right thing for this particular architecture, but wondering if there are cleaner ways of doing the right thing. (The file format is little endian; if it were big-endian, I'd probably just use the htons/htonl family.) Thanks. There is a full set of standard macros and functions for this in OSByteOrder.h : e.g. http://www.opensource.apple.com/source/xnu/xnu-1456.1.26

What endianness does Python use to write into files?

孤街浪徒 提交于 2019-12-03 20:27:11
When using file.write() with 'wb' flag does Python use big or litte endian, or sys.byteorder value ? how can i be sure that the endianness is not random, I am asking because I am mixing ASCII and binary data in the same file and for the binary data i use struct.pack() and force it to little endian, but I am not sure what happen to the ASCII data ! Edit 1: since the downvote, I'll explain more my question ! I am writing a file with ASCII and binary data, in a x86 PC, the file will be sent over the network to another computer witch is not x86, a PowerPC, witch is on Big-endian, how can I be sure

how to convert big-endian numbers to native numbers delphi

微笑、不失礼 提交于 2019-12-03 15:03:10
I want to know how to convert big-endian numbers to native numbers in Delphi. I am porting some C++ code in that I came across: unsigned long blockLength = *blockLengthPtr++ << 24; blockLength |= *blockLengthPtr++ << 16; blockLength |= *blockLengthPtr++ << 8; blockLength |= *blockLengthPtr; unsigned long dataLength = *dataLengthPtr++ << 24; dataLength |= *dataLengthPtr++ << 16; dataLength |= *dataLengthPtr++ << 8; dataLength |= *dataLengthPtr; I am not familiar with C++, so I don't understand what those operators do. Mason Wheeler Andreas's answer is a pretty good example of how to do it in

Details about Endian-ness and .Net?

点点圈 提交于 2019-12-03 14:41:13
问题 I have a few questions about endian-ness that are related enough that I warrant putting them in as one question: 1) Is endian-ness decided by .Net or by the hardware? 2) If it's decided by the hardware, how can I figure out what endian the hardware is in C#? 3) Does endian-ness affect binary interactions such as ORs, ANDs, XORs, or shifts? I.E. Will shifting once to the right always shift off the least significant bit? 4) I doubt it, but is there a difference in endian-ness from different

Endianness and Socket Programming in C

ぐ巨炮叔叔 提交于 2019-12-03 14:40:16
I'm making a program that communicate with certain patient monitor using C sockets. I'm using connection-less sockets (UDP) to communicate with the device. But there is endianness mis-match between my computer and device and so far I was doing this to get parse response from the patient monitor: recvfrom(int socket, char *buffer, size_t length, int flags, struct sockaddr *address, socklen_t *address_len); Then I was casting the buffer directly to structure and using the ntohs and ntohl to change the byte ordering, for example: struct A * a = (struct A *)buffer; Struct A b; b.v1 = ntohs(a->v1);

Reverse the Endianness of a C structure

China☆狼群 提交于 2019-12-03 14:15:27
问题 I have a structure in C that looks like this: typedef u_int8_t NN; typedef u_int8_t X; typedef int16_t S; typedef u_int16_t U; typedef char C; typedef struct{ X test; NN test2[2]; C test3[4]; U test4; } Test; I have declared the structure and written values to the fields as follows: Test t; int t_buflen = sizeof(t); memset( &t, 0, t_buflen); t.test = 0xde; t.test2[0]=0xad; t.test2[1]=0x00; t.test3[0]=0xbe; t.test3[1]=0xef; t.test3[2]=0x00; t.test3[3]=0xde; t.test4=0xdeca; I am sending this