zoukankan      html  css  js  c++  java
  • BYTE* To Float*

    char c = *(char*)pByte;
    short shrt = *(short*)(pByte+1);
    long lng = *(long*)(pByte+3);
    float flt = *(float*)(pByte+7);
    string str = (char*)(pByte+11);

    JohnEx:

    You are not converting char to float; rather you are interpreting a sequence of 4 bytes as a float. Not the same thing at all. There is no need to first interpret the sequence of bytes as a string, or to use memcpy.

    You have a BYTE stream, say pByte (a BYTE*), and the float value is at positions 7 through 10

    float f = *(float*)(pByte+7);

    Similarly for the other values

    char c = *(char*)pByte;
    short shrt = *(short*)(pByte+1);
    long lng = *(long*)(pByte+3);
    float flt = *(float*)(pByte+7);
    string str = (char*)(pByte+11);

    (assuming the string part is correctly null-terminated). I would write a single function to write these values into a struct, so the rest of the code can be clean.

  • 相关阅读:
    五,系统操作命令说明
    三,linux系统的由来
    二,服务器磁盘阵列(raid)
    一服务器硬件介绍
    四,元组类型
    集合类型
    字典类型
    三,列表类型
    二,字符串类型
    一,数字类型
  • 原文地址:https://www.cnblogs.com/mazhenyu/p/2255216.html
Copyright © 2011-2022 走看看