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

  • Home
  • SEARCH
  • 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 6242125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T11:53:58+00:00 2026-05-24T11:53:58+00:00

Just curious about something. While converting HTML colors (whose individual color components are represented

  • 0

Just curious about something. While converting HTML colors (whose individual color components are represented via 2-digit hexadecimal values) to floats between 0.0 and 1.0 so we can use them with OpenGL, I became curious about something. We have to divide the hex values by 255 to give us their OpenGL counterparts, but we can’t simply use the hex values as-is because that produces integer division.

Now I know these all work around this issue (of course)…

float r = 0xFD / (float)0xFF; // Works because of the cast to float

float r = 0xFD / 255.0f;      // Works because of the explicit float 

float d = 0xFF;
float r = 0xFD / d;           // Works because 'd' is a float 

…but I was wondering if there’s any way to just decorate a hex value so it’s interpreted as a float (like you do with the ‘f’ in 1.0f) without having to do casting, calculations or interim variables.

These of course don’t work…

float r = 0xFD / 0xFF;   // Integer division yields an integer, not float

float r = 0xFD / 0xFFf;  // Interprets 'f' as part of the hex value

Again, not trying to find out how to achieve my needed results as my code works just fine. I’m just wondering if I can make the code cleaner via decorating the hex value with something similar to how ‘f’ works with decimal values instead of using the above-three methods that do work.

  • 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-24T11:53:58+00:00Added an answer on May 24, 2026 at 11:53 am

    I’m afraid you have to use preprocessor definition in order to achieve the best look. And you need also casting to perform your computations.

    The best solution I can think is

    #define COMPONENT8(value) ((float)(value) / 255.0f))
    

    Floating point values cannot be specified as hexadecimal (integer) values.

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

Sidebar

Related Questions

i'm just curious about something.I'm using hsql in myproject (embedded of course).At some time
I'm just curious about the efficiency of pattern matching in Haskell. What is a
I'm just curious about this. It strikes me that the behavior of a StringBuilder
I'm just curious about this really, does anyone know why they broke convention on
I was just curious about the password mode display of the TextInput control in
This is mostly a theoretical question I'm just very curious about. (I'm not trying
I'm just curious to know about this.When i heard about Spring.net and tried some
I'm just curious what Afx stands for. And what about Fx in FxCop?
i'm just curious. so i ask this particular question about SQLite. I haven't use
... after having just read http://www.cocoadev.com/index.pl?CocoaInsecurity ... I am curious to know about your

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.