Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9141309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:37:41+00:00 2026-06-17T09:37:41+00:00

I have an array which has data which is mixed in format. It contains

  • 0

I have an array which has data which is mixed in format. It contains both unsigned ints & floats (all stored in a 4 byte data each).

I want to convert each 4 byte data to a float. However, none of the methods worked for me. For example.

union
{
   DWORD i;
   float f;
} u; 

This method doesn’t work. Neither does reinterpret_cast to float.

The data I have is like this.

{ 1, 8, 1.00000, -1.000000 }

I have a uint32_t pointer which points to the memory.

DWORD value = *(uint_pointer) gives me the 1, 8 correctly and not the others.
Using a typecast float causes 1.00000 & -1.00000 to be recognized correctly but not the other two.

I basically want the result to be

{ 1.00000, 8.00000, 1.00000, -1.00000 }

I looked at SO for all the previous answers but none of them worked reliably hence I am posting this again to get some ideas.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T09:37:42+00:00Added an answer on June 17, 2026 at 9:37 am

    You need to know which stretches of 4 bytes are floats and which stretches of 4 bytes are uints. If you don’t know, there is no way to convert them, unfortunately, they are just 32 bits with ambiguous meaning. However, if you do know that the third value is a float, for example, you can obtain it with float v3 = ((float *)uint_pointer)[3]. Also, you could check out my lengthy explanation in this previous post: Granular Synthesis in iOS 6 using AudioFileServices

    EDIT:
    If you don’t know that it is 4 bytes == sizeof(DWORD) == sizeof(float) that contain your values, and as a good practice in general, you could cast to u* and access it from the union. That way, you use the compiler’s knowledge of memory alignment, so v3 = ((u *)uint_pointer)[3].f is safer, see comment by @LightnessRacesInOrbit.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array which contains a great deal of data, which has been
I have an Array in PHP which contains data from database. And it prints
Ok, So I have a 2-d array of data which has the shape(23025, 1000),
I have a normal, boring old array which has a lot of data in
I have an array which has lots of data which is dispalyed on the
I have a Json array which has the elements below: adjacencies, data, id, name.
I have a txt file which has data in the below format: int string
i have AudioQueueBuffer 's Audio Data which has void * const format. i want
I have a variable (pvlist) an array which contains data like so ' 120123,345654
I have a structured array (1x1) called 'Data' which has 3 fields. Each field

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.