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 4 of 4

Thread: decimal and hexdecimal

  1. #1
    Junior Member
    Join Date
    Nov 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question decimal and hexdecimal

    how to know the input value of integer is decimal or hexdecimal


  2. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: decimal and hexdecimal

    you'll have to be more specific than that. Do you mean inside your Java source code? It will automatically be considered to be in decimal form if it looks like a number

    123 // valid decimal number
    154 // valid decimal number
    1a5 // invalid decimal number, compile error

    You must explicitly tell Java that a number is hexadecimal by putting an "0x" (that's a zero followed by a lower-case x).

    0x5d // valid hexadecimal number
    0x4efd // valid hexadecimal number
    0x100 // valid hexadecimal number

  3. #3
    Super Moderator Json's Avatar
    Join Date
    Jul 2009
    Location
    Warrington, United Kingdom
    Posts
    1,274
    My Mood
    Happy
    Thanks
    70
    Thanked 156 Times in 152 Posts

    Default Re: decimal and hexdecimal

    If you're not really curious about know what type it is but you just want it converted into an integer you can do this.

    Integer.decode("0x4efd")

    // Json

  4. #4
    Junior Member
    Join Date
    Nov 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Re: decimal and hexdecimal

    thanks

    and i have one more doubt

    if a is an integer variable, i can assign it as 0x5a5a5a it will print the decimal on console.
    and b is an integer variable , i can assign it 90. it will also print 90 on console.

    in that a is assigned by hex decimal so i want to divide hex decimal like 5a,5a ,5a
    and it will display on console 90,90,90

    is it possible

Similar Threads

  1. Converting Hex to Decimal
    By r2ro_serolf in forum Java Theory & Questions
    Replies: 10
    Last Post: September 4th, 2011, 04:29 PM
  2. Java program to format a double value to 2 decimal places
    By JavaPF in forum Java Programming Tutorials
    Replies: 3
    Last Post: December 4th, 2010, 04:08 PM
  3. decimal to hex
    By rsala004 in forum Algorithms & Recursion
    Replies: 1
    Last Post: November 3rd, 2009, 02:16 AM
  4. [SOLVED] How to use decimal place when formatting an output?
    By napenthia in forum Java Theory & Questions
    Replies: 2
    Last Post: April 27th, 2009, 03:17 AM