Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - Conversion between string and integer array in java
Conversion between string and integer array in java
Public class StringHex {

//If ENCODE_BITS = 8, Chinese character encoding is not supported, and 16 supports arbitrary character encoding.

Private static final int encode _ bits =16;

public string ex(){

}

Public static void main(String[] args) {

//To support all unicode characters, you need to use 16 bits to store the binary code of the characters.

String test = "@ dasd & amp% $ # $% # @ @ #" Hello, Casta, yes ";

System.out.println ("input string:"+test);

int[]is = string ex . string points(test);

system . out . print(" Encode arrays:");

for(int j: is) {

system . out . print(j);

}

system . out . println(" \ n decode String:"+String ex . intstostring(is));

}

Public static string intsToString(int [] ints) {

int [] ts = new int [StringHex。 ENCODE _ BITS];

string buffer sb = new string buffer();

for(int I = 0; I & ltint. length/string hex ENCODE _ BITSi ++) {

int j = i * StringHex。 ENCODE _ BITS

for(int k = j; k & ltj + StringHex。 ENCODE _ BITSk ++) {

ts[k-j]= ints[k];

}

sb . append(string hex . intstochar(ts));

}

return sb . tostring();

}

public static int[]String points(String dist){

int len = dist . length();

int [] ints = new int[StringHex。 ENCODE _ BITS * len];

for(int I = 0; I & ltleni ++) {

char[]cs = string hex . chart points(dist . charat(I))。 toCharArray();

int j = i * StringHex。 ENCODE _ BITS

for(int k = j; k & ltj + StringHex。 ENCODE _ BITSk ++) {

ints[k]= integer . parse int(cs[k-j]+" ");

}

}

Returns an integer;

}

Common static string chart point (char c) (

string bin = integer . tobinary string(c);

int len = StringHex。 ENCODE _ BITS-bin . length();

for(int I = 1; I<= leni++) {

bin = " 0 "+bin;

}

Recycling box;

}

public static char intsToChar(int[]ints){

Int code point = 0;

for(int I = ints . length; I>= 1; I-) {

codePoint += Math.pow(2,I- 1)* ints[ints . length-I];

}

return character . tochars(code point)[0];

}

}