User Profile

Collapse

Profile Sidebar

Collapse
Marijn Holtrop
Marijn Holtrop
Last Activity: Dec 23 '10, 12:40 AM
Joined: Dec 17 '10
Location:
  •  
  • Time
  • Show
  • Source
Clear All
new posts

  • Marijn Holtrop
    replied to How to convert 4 byte's to float?
    in C
    No it is not all that way so complicated. This runs inside a microcontroller and the message is transmitted by an iphone using the osc protocol (open sound control). It is all very well defined.
    Due to compatibillity with a specific iphone app I needed to convert the float. That app only supports the transmission of floats and my application could only handle integers so I needed a conversion.
    See more | Go to post

    Leave a comment:


  • Marijn Holtrop
    replied to How to convert 4 byte's to float?
    in C
    I thought a float was always 4 bytes long. It would also be possible to test the length of val but the result is only 4 bytes long.

    memcpy(&val,&re sult, sizeof val);

    The 4 bytes in the buffer came from an utp buffer.
    See more | Go to post

    Leave a comment:


  • Marijn Holtrop
    replied to How to convert 4 byte's to float?
    in C
    ah found the result:
    Code:
    // read an unsigned long int from 4 bytes in buffer,
    // starting at offset, MSB first
    float readfloat(byte * buffer, int offset) {
    
      float val=0;
    
      unsigned long result=0;
      result |= ((unsigned long)(buffer[offset]) << 0x18);
      result |= ((unsigned long)(buffer[offset+1]) << 0x10);
      result |= ((unsigned long)(buffer[offset+2])
    ...
    See more | Go to post

    Leave a comment:


  • Marijn Holtrop
    started a topic How to convert 4 byte's to float?
    in C

    How to convert 4 byte's to float?

    I'm adapting a piece of code. The original code takes 4 bytes and convert that to an integer.
    In my case this memory contains a float and I want the function to return a float.
    Here is the original code:

    Code:
    // read an unsigned long int from 4 bytes in buffer,
    // starting at offset, MSB first
    unsigned long readLongInt(byte * buffer, int offset) {
      unsigned long result=0;
      result |= ((unsigned
    ...
    See more | Go to post
No activity results to display
Show More
Working...