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

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -