[Solved] How to convert "Bytecode" to ASCII

Hi, guys! How are you? Is it possible to translate bytecode into ASCII characters? With "bytecode" - I don't know if the name is the correct one - I mean the data transferred in packets from the low level protocols. Ex: 47 45 54 20 2f 20 48 54 54 50 2f 31 2e 31 I am starting my studies in networks and I have been trying to create a translator. I've already managed - I imagine - to transform ASCII into bytecode, but I'm having problems with the opposite. I can't think of a way to turn a byte (eg, 0x47) into anything that will allow me to convert it to a character. My progress so far: https://code.sololearn.com/ck6BbSIAF13c/#py (Sorry for not attaching the code, I'm using the desktop version of the site.) I am also avoiding using any external library in order to understand how it works from the bottom up.

26th Jun 2020, 10:01 PM
rfPeixoto - avatar
4 Respuestas
+ 5
0x47 is Hex representation you can convert it to int by int("0x47",16) Then using chr on it
26th Jun 2020, 10:15 PM
Abhay - avatar
+ 3
Thank you so much guys! Sorted out! Abhay: I didn't know it was possible to pass these arguments on to the int function, thank you very much! Dennis: Machine code seems to be more complex haha. I'll take a look when you understand this here, thank you very much. G B: Precisely. I intend to increase the code. I want him to identify and separate the bytes of each protocol to translate and show the headers very separately. A lot is missing, thank you!
26th Jun 2020, 10:24 PM
rfPeixoto - avatar
+ 2
You could use chr(), which is the counter part of ord()... To go from bottom up, you might determine, whether it is a upper or lower case (A is ASCII 65, a is ASCII 97, z/ should be a + 25), deduct the respective offset (65 or 97) and then you have the index for a list, which contains A-Z ( a-z)...
26th Jun 2020, 10:17 PM
G B - avatar
+ 1
I don't know python, but just checking here because bytecode isn't really related to ASCII. It's code that's supposed to be interpreted. For example the sequence 04 90 E6 11 F5 E8 50 on a gameboy ( I know it's not bytecode, but actual machine code, but it pretty much works the same way and I have the actual machine code next to me anyway ) Would mean 04 - Increment B register by 1 90 - Decrement B register by 1 E6 11 - And A register with 0x11 ( 2 byte instruction ) F5 - Push AF register to the stack E8 50 - Add 0x50 to the stack pointer ( also 2 byte instruction )
26th Jun 2020, 10:12 PM
Dennis - avatar