This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

BYTES

hi
In language C, how I can obtain each BYTE of a number floating point located in XDATA.
Example:
If number is -12.5

Address 0 1 2 3
Content 0xC1 0x48 0x00 0x00

How I can consent to each BYTE (0 1 2 3) and to keep it in a variable type char or to write each byte of the number in a port.
Some technique exists as XBYTE or something like that....

Thank you,

  • First, read the section in the manual on data storage formats.
    That tells you how the individual bytes are laid-out within a larger data item.

    Then construct a union containing the float and an appropriate set of bytes.
    Or do it via abstact pointers.

    Remember that this is unlikely to be portable - if you wanted to move to another compiler, you'd have to read the section in the other compiler's manual on data storage formats and possibly re-construct your union.

  • How about:

    union fb
      {
      float f;
      unsigned char c[4];
      };
    
    union fb = 12.5;
    

    Then fb.c[0], fb.c[1], fb.c[2], and fb.c[3] will be the 4 bytes of the float.

    Jon

  • I think it's similar to obtaining each BYTE of a number floating point located in inner DATA. Firstly make sure the address for each byte,and then pass it back.For example,
    mode = chCmdChannel;
    here,mode is a inner variable,
    chCmdChannel is a address.



  • I think it's similar to obtaining each BYTE of a number floating point located in inner DATA. Firstly make sure the address for each byte,and then pass it back.For example,
    mode = chCmdChannel;
    here,mode is a inner variable,
    chCmdChannel is a address variable locating in XDATA.