how to know the input value of integer is decimal or hexdecimal
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.
how to know the input value of integer is decimal or 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
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
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