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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:21:32+00:00 2026-06-18T04:21:32+00:00

This is my method for converting a String Hex to a decimal: private int

  • 0

This is my method for converting a String Hex to a decimal:

private int fromHexToPercent(String hex){
    int decimal = Integer.parseInt(hex, 16);
    return decimal;
}

When i call it on these values: #ffe87e, #ffc6bb, #528b7a, #9b81ff, #7d6a32, #000c40 among others I get the following exception on this line:

   int decimal = Integer.parseInt(hex, 16);

Error:

at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
    at java.lang.Integer.parseInt(Integer.java:481)

Here is my method for converting from rgb to hex, i got a feeling that Java has å problem with this line: hex = “0” + hex;. But it needs to be there to get the hex-code right.

    public static String toHex(int r, int g, int b) {
return "#" + toBrowserHexValue(r) + toBrowserHexValue(g) +  toBrowserHexValue(b);
}

private static String toHexValue(int number) {
    String hex = Integer.toHexString(number & 0xff);
    while (hex.length() < 2) {
        hex = "0" + hex;
    }
    return hex;
}

Really hope somebody can see a solution to this problem =)

  • 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-18T04:21:34+00:00Added an answer on June 18, 2026 at 4:21 am

    The only valid hex digits are 0-9 and a-f (or A-F). # is not a valid hex digit.

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

Sidebar

Related Questions

Can this method work? public String sayHello(){ return Hello.jsp?name= + laala; } I am
I have the following method: public IEnumerable<Foo> GetFoo(int x, string y) { return from
I'm trying to write suitable method of converting appengine/datastore.Time type to string. This type
I have method for converting array of Booleans to integer. It looks like this
This is a follow on from: Python - Converting Hex to INT/CHAR I now
Is there a static method for converting a string, int, etc. into a byte/byte
Take this method /** * @return List of group IDs the person belongs to
In this method I return a value of the type Double, but there is
Is there an efficient method of converting an integer into the written numbers, for
I'm using Asp.Net-Mvc, I have this method in my controller: [AcceptVerbs(HttpVerbs.Post)] public ActionResult LinkAccount(string

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.