Java tutorial
//package com.java2s; //PduUtils is distributed under the terms of the Apache License version 2.0 public class Main { public static final int ADDRESS_NUMBER_PLAN_ID_TELEPHONE = 0x01; public static final int ADDRESS_TYPE_UNKNOWN = 0x00; public static final int ADDRESS_TYPE_INTERNATIONAL = 0x10; public static final int ADDRESS_TYPE_ALPHANUMERIC = 0x50; public static int getAddressTypeFor(String address) { boolean international = false; // strip any + to simplify checks // but presence of + automatically assumes an // international style address if (address.startsWith("+")) { international = true; address = address.substring(1); } for (int i = 0; i < address.length(); i++) { if (!Character.isDigit(address.charAt(i))) { // check if alphanumeric return createAddressType(ADDRESS_TYPE_ALPHANUMERIC); } } if (international) { return createAddressType(ADDRESS_TYPE_INTERNATIONAL | ADDRESS_NUMBER_PLAN_ID_TELEPHONE); } else { return createAddressType(ADDRESS_TYPE_UNKNOWN | ADDRESS_NUMBER_PLAN_ID_TELEPHONE); } } public static int createAddressType(int addressType) { // last bit is always set return 0x80 | addressType; } }