1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 /* 23 * ident "%Z%%M% %I% %E% SMI" 24 * 25 * Copyright (c) 2001 by Sun Microsystems, Inc. 26 * All rights reserved. 27 */ 28 29 package com.sun.dhcpmgr.cli.common; 30 31 /** 32 * This class contains common utilites used by the CLI programs. 33 */ 34 public class Util 35 { 36 /** 37 * Array of hex characters, used by for translations. 38 */ 39 private static final char hexChars[] = {'0', '1', '2', '3', '4', '5', '6', 40 '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; 41 42 /** 43 * Converts an ascii string into a string containing its hex value. 44 * @param ascii the ascii representation 45 * @return the hex representation 46 */ 47 public static String asciiToHex(String ascii) { 48 49 StringBuffer hex = new StringBuffer(); 50 51 if (ascii == null) { 52 return null; 53 } 54 55 for (int i = 0; i < ascii.length(); i++) { 56 char aChar = ascii.charAt(i); 57 int ndx = (aChar >> 4) & 0x000f; 58 hex.append(hexChars[ndx]); 59 ndx = aChar & 0x000f; 60 hex.append(hexChars[ndx]); 61 } 62 63 return hex.toString(); 64 65 } // asciiToHex 66 67 } // Util