Here you can find the source of convertHexLong(String hex)
Parameter | Description |
---|---|
hex | a string. |
public static long convertHexLong(String hex)
//package com.java2s; /******************************************************************************* * Copyright (c) 2014 Liviu Ionescu.//w ww . j a v a2s.c o m * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * Liviu Ionescu - initial version *******************************************************************************/ public class Main { /** * Convert hex to long. Considers +/-, ignores 0x and 0X. * * @param hex * a string. * @return a long. */ public static long convertHexLong(String hex) { boolean isNegative = false; if (hex.startsWith("+")) { hex = hex.substring(1); } else if (hex.startsWith("-")) { hex = hex.substring(1); isNegative = true; } if (hex.startsWith("0x") || hex.startsWith("0X")) { hex = hex.substring(2); } long value = Long.valueOf("0" + hex, 16); if (isNegative) value = -value; return value; } }