Here you can find the source of textToBytes(String text)
Parameter | Description |
---|---|
text | a parameter |
private static byte[] textToBytes(String text)
//package com.java2s; public class Main { /**//from w ww . ja va 2s .c o m * Convert text to bytes * * @param text * @return bytes for the input text */ private static byte[] textToBytes(String text) { byte[] baBytes = new byte[text.length() / 2]; for (int j = 0; j < text.length() / 2; j++) { Integer tmpInteger = Integer.decode(new String("0x" + text.substring(j * 2, (j * 2) + 2))); int tmpValue = tmpInteger.intValue(); if (tmpValue > 127) // fix negatives { tmpValue = (tmpValue - 127) * -1; } tmpInteger = new Integer(tmpValue); baBytes[j] = tmpInteger.byteValue(); } return baBytes; } }