Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

check hex string contains only hex bounded values

Tags:

java

string

hex

How to check a given hex string contains only hex number. is there is any simple method or any java library for the same?i have string like "01AF" and i have to check string only contains hex range values,for that what i am doing now is take the string and then split the string and then converted it to appropriate format then make a check for that value.is there is any simple method for that?

like image 594
Anandhu Avatar asked Mar 31 '26 02:03

Anandhu


1 Answers

try
{
    String hex = "AAA"
    int value = Integer.parseInt(hex, 16);  
    System.out.println("valid hex);
 }
 catch(NumberFormatException nfe)
 {
    // not a valid hex
    System.out.println("not a valid hex);
 }

This will throw NumberFormatException if the hex string is invalid.

Refer the documentation here

like image 128
Kakarot Avatar answered Apr 02 '26 03:04

Kakarot



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!