byte array converted to double type

Source: Internet
Author: User
Example

Byte[] ByteArray = {64, 47, 215, 10, 61, 112, 163, 215}; Array.reverse (ByteArray);

var result = bitconverter.todouble (ByteArray, 0); Result is 15.92 byte conversion

Bitconverter.todouble method (byte[], Int32)

Returns the position specified in a byte array of eight byte conversions of a double-precision floating-point number.

public static double ToDouble (
	byte[] value,
	int startIndex
)
Parameter: value, type:system.byte[] byte array. StartIndex, Type:System.Int32, the starting position within the value. Return value: Type:System.Double, a double-precision floating-point number startIndex consisting of eight bytes starting. The ToDouble method converts the byte conversion from the index StartIndex to the StartIndex + 7 to the Double value. The order in the byte array must reflect the architecture of the computer system;

The order is reflected by the Bitconverter.islittleendian field to indicate the byte order ("Endianness") in which the data is stored in this computer architecture. True if the architecture is Little-endian, or false if the architecture is Big-endian.

Little-endian and Big-endian

A) Little-endian is the low byte emissions in the memory of the lower address end, high byte emissions at the high address of memory.
b Big-endian is the high byte emissions in the memory of the low address end, low byte emissions in the memory of the higher address.

In memory: Stacks are growing downward, while the heap is growing upwards.

Assign a unsigned char buf[4] on the stack, then how does the array variable be laid out on the stack? Look at the picture below:
Bottom of stack (high address)
----------
BUF[3]
BUF[2]
BUF[1]
BUF[0]

----------
Top of stack (low address)


In the decimal we all say that the left side is high, the right side is low, in other systems as well. Take 0x12345678 to say,

The bytes from high to low are sequentially 0x12, 0x34, 0x56, and 0x78.

Take the unsigned int value = 0x12345678 as an example, to see the storage situation in both byte order, we can use unsigned char buf[4] to represent value:

Little-endian: Lower address storage low, as shown below:
Bottom of stack (high address)
---------------
BUF[3] (0x12)--high
BUF[2] (0x34)
BUF[1] (0x56)
Buf[0] (0x78)--Low
--------------
Top of stack (low address)

Big-endian: Low address storage high , as shown below:
Bottom of stack (high address)
---------------
BUF[3] (0x78)--Low
BUF[2] (0x56)
BUF[1] (0x34)
Buf[0] (0x12)--high
---------------
Top of stack (low address)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.