How to get a float number of two bytes? There are two bytes. Suppose 0x02 is the lowest part and 0x04 is the highest part. How do I get a float number?
Closed due to the fact that the essence of the issue is not clear to the participants of Kromster , Denis Bubnov , aleksandr barakin , vp_arth , αλεχολυτ 9 Apr '17 at 19:22 .
Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .
- 2What should be the resulting number? - Yaant
- bytes must be cast in one way or another into an array of bytes. Then, using BitConvert. - Garrus_En
- one@Garrus_En So the author does not need an int, but a float. - Yaant
- The length of the float type is four bytes, not two. Something you do not agree. - Alexander Petrov
- I agree with the previous answer, read the specification on float ru.wikipedia.org/wiki/… . Here, perhaps two bytes are always zero, then you can use unmanaged code - Alexsandr Ter
|
1 answer
Suppose your number is represented like this:
float f = 2.7f; // Приводим float к массиву байт byte[] arr = BitConverter.GetBytes(f); // И обратный процесс float i = BitConverter.ToSingle(arr,0); Hope to help understand.
- float i = BitConvert.ToSingle (arr, 0); - Dmitry Chistik
- I will correct in the answer, thanks. Although Int16 is the same 2 bytes in size - Garrus_En
- only they are stored in a different memory ... - Dmitry Chistik
- And how to correctly convert? Is the order itself important when converting? - Victor Sayapov
- not clear comment, what do you mean? What does it mean to convert correctly? I gave an example of converting from float to byte and back. - Garrus_En
|