Here you can find the source of fromHex(String input, int max)
Parameter | Description |
---|---|
input | String |
max | Maximum permitted value |
Parameter | Description |
---|---|
IllegalArgumentException | If it's invalid or out of range |
private static int fromHex(String input, int max) throws IllegalArgumentException
//package com.java2s; /*//from w ww .j av a 2 s .c o m This file is part of leafdigital browserstats. browserstats is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. browserstats is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with browserstats. If not, see <http://www.gnu.org/licenses/>. Copyright 2010 Samuel Marshall. */ public class Main { /** * Converts a string from hex to integer. * @param input String * @param max Maximum permitted value * @return Number * @throws IllegalArgumentException If it's invalid or out of range */ private static int fromHex(String input, int max) throws IllegalArgumentException { try { int value = Integer.parseInt(input.toLowerCase(), 16); if (value < 0 || value > max) { throw new IllegalArgumentException("Out of range: " + input); } return value; } catch (NumberFormatException e) { throw new IllegalArgumentException("Not valid hex: " + input); } } }