java什么数组能村浮点数_c脚本怎样把字节数组转换成浮点数
///
/// 將二進制值轉(zhuǎn)ASCII格式十六進制字符串
///
///
二進制值
///
定長度的二進制
/// ASCII格式十六進制字符串
public static string toHexString(int data, int length)
{
string result = "";
if (data > 0)
result = Convert。
ToString(data, 16)。ToUpper();
if (result。Length
/// 將浮點數(shù)轉(zhuǎn)ASCII格式十六進制字符串(符合IEEE-754標準(32))
///
///
浮點數(shù)值
/// 十六進制字符串
public static string FloatToIntString(float data)
{
byte[] intBuffer = BitConverter。
GetBytes(data);
StringBuilder stringBuffer = new StringBuilder(0);
for (int i = 0; i
/// 將ASCII格式十六進制字符串轉(zhuǎn)浮點數(shù)(符合IEEE-754標準(32))
///
///
16進制字符串
///
public static float StringToFloat(String data)
{
if (data。
Length 8)
{
//throw new NotEnoughDataInBufferException(data。length(), 8);
return 0;
}
else
{
byte[] intBuffer = new byte[4];
// 將16進制串按字節(jié)逆序化(一個字節(jié)2個ASCII碼)
for (int i = 0; i
/// 將byte數(shù)組轉(zhuǎn)為浮點數(shù)
///
///
byte數(shù)組
///
public static float ByteToFloat(byte[] bResponse)
{
if (bResponse。
Length 4)
{
//throw new NotEnoughDataInBufferException(data。length(), 8);
return 0;
}
else
{
byte[] intBuffer = new byte[4];
//將byte數(shù)組的前后兩個字節(jié)的高低位換過來
intBuffer[0] = bResponse[1];
intBuffer[1] = bResponse[0];
intBuffer[2] = bResponse[3];
intBuffer[3] = bResponse[2];
return BitConverter。
ToSingle(intBuffer, 0);
}
}
///
/// 用指針方式強制將byte數(shù)組轉(zhuǎn)為浮點數(shù)
///
///
///
public static float BytetoFloatByPoint(byte[] bResponse)
{
//uint nRest = ((uint)response[startByte]) * 256 ((uint)response[startByte 1]) 65536 * ((uint)response[startByte 2]) * 256 ((uint)response[startByte 3]);
float fValue = 0f;
uint nRest = ((uint)bResponse[0]) * 256
((uint)bResponse[1])
65536 * (((uint)bResponse[2]) * 256 ((uint)bResponse[3]));
//用指針將整形強制轉(zhuǎn)換成float
unsafe
{
float* ptemp;
ptemp = (float*)(&nRest);
fValue = *ptemp;
}
return fValue;
}。
全部
總結(jié)
以上是生活随笔為你收集整理的java什么数组能村浮点数_c脚本怎样把字节数组转换成浮点数的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 网页前端套java数据_【java】网页
- 下一篇: php 数组美化_php 打印数组格式化