Java tutorial
//package com.java2s; public class Main { public static final int parseUnsignedIntAttribute(CharSequence charSeq) { String value = charSeq.toString(); int index = 0; int len = value.length(); int base = 10; if ('0' == value.charAt(index)) { // Quick check for zero by itself if (index == len - 1) { return 0; } char c = value.charAt(index + 1); if ('x' == c || 'X' == c) { // check for hex index += 2; base = 16; } else { // check for octal index++; base = 8; } } else if ('#' == value.charAt(index)) { index++; base = 16; } return (int) Long.parseLong(value.substring(index), base); } }