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 3222916
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T16:02:48+00:00 2026-05-17T16:02:48+00:00

I am new to programming, I’ve done web development, but I am currently trying

  • 0

I am new to programming, I’ve done web development, but I am currently trying to learn real programming. The question I have is already answered here.

union ufloat {
  float f;
  unsigned u
};

ufloat u1;
u1.f = 0.3f;

What I don’t get is how it works. What does the 0.3 part do? I couldn’t find it in my text. And how does this convert a float to binary? Because cout<<u1.u; doesn’t seem to give me the answer. Can someone help?

  • 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-05-17T16:02:48+00:00Added an answer on May 17, 2026 at 4:02 pm

    0.3 is just a test value. Printing u1.u will not give you the binary representation, but the value of the binary representation interpreted as a base 10 integer. To get the binary value, you have to convert u1.u to binary.

    Another way you can do the conversion is by using bitwise operators.

    For example:

    unsigned x = 11;
    do
    {
        cout << (x & 1); // print last bit
        x = x >> 1; // get rid of the printed bit
    } while ( x );
    

    Note that this will print the bits in reverse order (least significant first). I’ll leave it up to you to fix this (you can use recursion or store values in an array and then print the array reversed).

    I also suggest you read about unions. Basically, the unsigned will occupy the same memory space as the float, allowing you to circumvent the restrictions of using bitwise operators to find the binary representation of the float.

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

Sidebar

Related Questions

i been thinking of a new programming language. Before trying to implement it i
Im new to programming and I dont know very much about but I'm making
I'm fairly new at programming, but I've wondered how shell text editors such as
We have 2 new GIS programmer/analyst in our department (new to programming and ArcObjects)
New to Linux programming in general. I am trying to communicate with a kernel
I'm new to windows programming and I'm trying to get notified of all changes
I have an interesting idea for a new programming language. It's based on a
What is the real benefit of creating a new programming language? It is highly
I always believed that when starting to learn a new programming language programmer must
It seems that most new programming languages that have appeared in the last 20

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.