Python ByteToHex Java Conversion -


hey have bytetohex converter in python , wanted convert java , have no idea how attempts have failed i've come here.. here code

def bytetohex( bytestr ):      return ' '.join( [ "%02x" % ord( x ) x in bytestr ] ) 

i wanna know how in java method

edit

i have string send on socket , this

string hexstr = "\\x7e\\x00\\x0c\\x01\\x00\\xa5\\xbd\\x00\\x7e\\x01\\x00\\x40\\x2d\\x00\\x3f\\x71"; 

then tried write method jsut converts string this.

7e 00 16 a1 c5 dd 39 02 7e 00 01 e7 2d 0a 00 23 41 1b 6c 11 b9 b9 b9 ba 3b e8 

just simple string array no 'x' , no '\' tried doing in java...

public byte[] bytetohex(string hexx) {     byte [] b;     hexx.replace("\\", "");      (int = 0; < hexx.length(); i++) {         hexx.replace("\\", "");         b[i] = char(i) + b.add(i +1);     } } 

but thats not right , cant figure out.

solution

just going old questions , answering them.

public static string bytetohex (string hex) {     return hex.replace("\\x", " "); } 

Comments

Popular posts from this blog

java - HTTP Status 500 - An exception occurred processing JSP page /second.jsp at line 15 -

SQL Server - MyCTE query based on 24 hour period (next day) -

php - Using str_replace to translate a MySQL Table in html -