endianness

convert int to char array Big Endian

放肆的年华 提交于 2019-12-02 09:04:08
I found this code on SO. unsigned char * SerializeInt(unsigned char *buffer, int value) { /* Write big-endian int value into buffer; assumes 32-bit int and 8-bit char. */ buffer[0] = value >> 24; buffer[1] = value >> 16; buffer[2] = value >> 8; buffer[3] = value; return buffer + 4; } You can see the code claims it is writing an integer into the buffer, in a Big Endian Way. My question is: Does this function work correctly on both Little endian and Big endian machines? In other words, on both LE and BE machines, does it store the number to buffer in a Big Endian Way ? And if yes, Why? Whatever

Converting float values of big endian to little endian using C#

北城以北 提交于 2019-12-02 06:31:00
问题 Is it possible to convert floats from big to little endian? I have a value from a big endian platform that I am sending via UDP to a Windows process (little endian). This value is a float, but when I am trying BitConverter.ToSingle I always get 5.832204E-42, but it should be 36.000. What am I doing wrong? Here is a code snipped: // Receive thread private void ReceiveData() { int count = 0; IPEndPoint remoteIP = new IPEndPoint(IPAddress.Parse("10.0.2.213"), port); client = new UdpClient

converting bits in to integer

狂风中的少年 提交于 2019-12-02 05:35:44
I receive a datapacket containing a byte array and I have to get some integer values from it. Here is a part of the documentation. Can someone help me please? This comes in a 4-byte array. Year from 1990 to 2052 (6 bit), Month from 1 to 12 (4 bit), Day from 1 to 31 (5 bit), Hour from 0 to 23 (5 bit), Minute from 0 to 59 (6 bit), Second from 0 to 59 (6 bit) Default value: 1 January 2000, 12:00:00 The format of the message is in little endian. What you need is some bitwise operations. First, construct an int out of the bytes: int n = b[0] | (b[1] << 8) | (b[2] << 16) | (b[3] << 24); Then, chop

most common way to deal with endianness and files C++

非 Y 不嫁゛ 提交于 2019-12-02 05:28:08
问题 I started out just reading/writing 8-bit integers to files using chars. It was not very long before I realized that I needed to be able to work with more than just 256 possible values. I did some research on how to read/write 16-bit integers to files and became aware of the concept of big and little endian. I did even more research and found a few different ways to deal with endianness and I also learned some ways to write endianness-independent code. My overall conclusion was that I have to

How is data stored on disk? - EFI GUID

ε祈祈猫儿з 提交于 2019-12-02 05:04:24
问题 I posted this question earlier on SuperUser but I feel it is more suited for programmers. If I understand correctly, according to GPT, the first 16 bytes of LBA 2 is the partition type GUID for the first partition on disk. In Windows Disk Management the first partition is designated as an EFI System Partition. However upon further investigation an EFI System Partition's GUID is: C12A7328-F81F-11D2-BA4B-00A0C93EC93B And yet the first 16 bytes tell me otherwise: 28732AC1-1FF8-D211-BA4B

Java: Efficiently converting an array of longs to an array of bytes

徘徊边缘 提交于 2019-12-02 04:29:03
问题 I have an array of longs I want to write to disk. The most efficient disk I/O functions take in byte arrays, for example: FileOutputStream.write(byte[] b, int offset, int length) ...so I want to begin by converting my long[] to byte[] (8 bytes for each long ). I'm struggling to find a clean way to do this. Direct typecasting doesn't seem allowed: ConversionTest.java:6: inconvertible types found : long[] required: byte[] byte[] byteArray = (byte[]) longArray; ^ It's easy to do the conversion

How is data stored on disk? - EFI GUID

北城余情 提交于 2019-12-02 01:02:37
I posted this question earlier on SuperUser but I feel it is more suited for programmers. If I understand correctly, according to GPT, the first 16 bytes of LBA 2 is the partition type GUID for the first partition on disk. In Windows Disk Management the first partition is designated as an EFI System Partition. However upon further investigation an EFI System Partition's GUID is: C12A7328-F81F-11D2-BA4B-00A0C93EC93B And yet the first 16 bytes tell me otherwise: 28732AC1-1FF8-D211-BA4B-00A0C93EC93B Interestingly the first 3 sections act as little endian while the other 2 are big endian. Why is

Converting a big.Int to little-endian byte slice

放肆的年华 提交于 2019-12-01 22:29:21
问题 I have a big.Int and want to convert it to a little-endian byte slice. If I use Int.Bytes, I get the big-endian byte slice. Is there any way to get little-endian byte slice for big.Int? 回答1: The simplest solution is to reverse the slice returned from Bytes() : b := bigInt.Bytes() for i := 0; i < len(b)/2; i++ { b[i], b[len(b)-i-1] = b[len(b)-i-1], b[i] } 来源: https://stackoverflow.com/questions/51123309/converting-a-big-int-to-little-endian-byte-slice

Determine the endianness of a numpy array

倖福魔咒の 提交于 2019-12-01 21:54:45
I have a numpy.array and I want to find out what endianness is used in the underlying representation. A byteorder property is documented here , but none of the given examples show it being used with an array. byteorder is a data type objects dtype attribute so you need to do this: In [10]: import numpy as np In [11]: arr = np.array([1,2,3]) In [12]: arr.dtype.byteorder Out[12]: '=' 来源: https://stackoverflow.com/questions/34097845/determine-the-endianness-of-a-numpy-array

fread/fwrite size and count [duplicate]

丶灬走出姿态 提交于 2019-12-01 17:27:27
问题 This question already has answers here : fwrite() - effect of size and count on performance (3 answers) Closed 2 years ago . I have doubts about which order of the parameters size and count to use for fread/fwrite. If I want to read 8kb of data from file fp, which of the following is more efficient? fread(data,1,8192,fp) fread(data,8192,1,fp) Also are there endiannes issues that I should be worried about? 回答1: They're exactly equivalent. As for endianness, it depends on what you're reading.