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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:51:12+00:00 2026-05-25T21:51:12+00:00

I may be making something incredibly simple incredibly complicated, but nothing I’ve tried so

  • 0

I may be making something incredibly simple incredibly complicated, but nothing I’ve tried so far seems to work.

I have NSStrings like @”BD8F60″ and I would like to turn them into ints like: r = 189, g = 143, b = 96.

Have found ways to convert hex values that are already ints into rgb ints, but am stuck on how to change the NSString with the letters in it into an int where the letters have been converted to their numerical counterparts. Apologize in advance if this is incredibly basic–I’m still learning this stuff at an incredibly basic level.

  • 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-25T21:51:12+00:00Added an answer on May 25, 2026 at 9:51 pm

    You need to parse the NSString and interpret the hex values.

    You may do this in multiple ways, one being using an NSScanner

    NSScanner* scanner = [NSScanner scannerWithString:@"BD8F60"];
    int hex;
    if ([scanner scanHexInt:&hex]) {
      // Parsing successful. We have a big int representing the 0xBD8F60 value
      int r = (hex >> 16) & 0xFF; // get the first byte
      int g = (hex >>  8) & 0xFF; // get the middle byte
      int b = (hex      ) & 0xFF; // get the last byte
    } else {
      NSLog(@"Parsing error: no hex value found in string");
    }
    

    There are some other possibilities like splitting the string in 3 and scan the values separately (instead of doing bitwise shift and masking) but the idea remains the same.

    Note: as scanHexInt: documentation explains, this also works if your string is prefixed with 0x like @"0xBD8F60". Does not automatically work with strings prefixed by a hash like @"#BD8F60". Use a substring in this case.

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

Sidebar

Related Questions

I think I may have misunderstood something here... But here goes. I'm using the
I may be missing something really simple here, but I am trying to style
This may be waaay to specific for SO, but there seems to be a
I may well be missing something here but I'm noticing very slow performance when
I think this may sound very straight forward, but still something is not working
So far I have been just playing around with the Addon SDK and making
I'm new to Telerik MVC controls, so this may be something simple. I started
I'm making a web app. In it there are times when a form may
May be I am getting old, but I can't find it...
May be a stupid questions but can I protect a row of data in

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.