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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T03:45:17+00:00 2026-06-04T03:45:17+00:00

How can I get single bits (or an entire variable) of a double or

  • 0

How can I get single bits (or an entire variable) of a double or a float?

For example if I have
float a = 0.5;

I would expect a String equal to:
"00111111000000000000000000000000"

or in hex:
"F000000"

  • 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-04T03:45:18+00:00Added an answer on June 4, 2026 at 3:45 am

    For Java, a float is on 32 bits like a int, and a double is on 64 bits like a long. Finding the binary representation of these numbers, you need to:

    float a = 0.5f;
    int bits = Float.floatToIntBits(a);
    String.format("%32s", Integer.toBinaryString(bits)).replace(" ", "0");
    String.format("%8s", Integer.toHexString(bits)).replace(" ", "0");
    

    "00111111000000000000000000000000" bit representation (32 bits)
    "3f000000" hexadecimal representation (32 bits)

    double a = 0.5d;
    long bits = Double.doubleToLongBits(a);
    String.format("%64s", Long.toBinaryString(bits)).replace(" ", "0");
    String.format("%16s", Long.toHexString(bits)).replace(" ", "0");
    

    "0011111111100000000000000000000000000000000000000000000000000000" bit representation (64 bits)
    "3fe0000000000000" hexadecimal representation (64 bits)

    You can check that it works by doing the reverse operation:

    int bits = Integer.parseInt("00111111000000000000000000000000", 2);
    Float.intBitsToFloat(bits);
    

    0.5 (float)

    long bits = Long.parseLong("0011111111100000000000000000000000000000000000000000000000000000", 2);
    Double.longBitsToDouble(bits);
    

    0.5 (double)

    For the hexadecimal representation, you can use respectively Integer.parseInt("...", 16); and Long.parseLong("...", 16);

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

Sidebar

Related Questions

If I have a single vector, I can get the 1st occurrence which is
I was just wondering how I can get a single tap to undo the
Can anyone get me with the regular expression to strip multiline comments and single
How can I get several GridViews on a single page to share the same
The getRGB() method returns a single int. How can I get individually the red,
Can I capture the following two routes in a single line? GET /game controllers.Main.app.gamelist
I can't get single key shortcuts to work properly in PyQt on Mac. For
Ok, so you can get a single value by dictionary[key] or all values by
Is this possible? $d=date(D); ... else if ($d=='(Thu|Fri|Sat)') { I can get a single
I would like to know if I can get the average of a sum

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.