Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Convert string hex to int?

  1. #1
    Junior Member
    Join Date
    Mar 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Convert string hex to int?

    Hello. I have searched for a long time now, but i'm stumped. How can I change the string 0xff00ff or whatever to the int 0xff00ff? I tried all of the normal converting methods, but can't seem to get this to work. You guys are my last hope. Thanks.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,049
    Thanks
    52
    Thanked 2,280 Times in 2,251 Posts

    Default Re: Convert string hex to int?

    How would you do it manually?
    Take the digit characters one at a time from the left and get their hex value and use those hex values to build the int value.
    First problem is converting a digit character to a hex value. '0' is 0, 'a' is 10
    Once you have the hex value then think about how to build the final value given a string of hex values left to right.
    Think about how its done with a decimal number. Given "123" you'd get the 1 first and then multiply that by 10 and add the 2 and then multiply that by 10 and add the 3 giving 123.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. [SOLVED] convert int to String
    By itispj in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 14th, 2011, 10:34 PM
  2. [SOLVED] convert String to int
    By b109 in forum Java Theory & Questions
    Replies: 3
    Last Post: June 3rd, 2010, 03:05 AM
  3. Conversion of string into integer in Java
    By JavaPF in forum Java Programming Tutorials
    Replies: 17
    Last Post: January 23rd, 2010, 08:33 AM
  4. Conversion of string into integer in Java
    By JavaPF in forum Java Code Snippets and Tutorials
    Replies: 17
    Last Post: January 23rd, 2010, 08:33 AM
  5. Convert string to int?
    By connex in forum Java Theory & Questions
    Replies: 1
    Last Post: December 9th, 2009, 04:06 AM