You are a life savor...i read all the documents and blogs but didn't understand a thing...and then i decided to watch your video...thanks and keep it up !!!
I have a bytearray(b'\x01\x03\x01) and when I try to .append(0x31) I get a bytearray(b'\x01\x03\x01\x011) Why not bytearray(b'\x01\x03\x01\x31 ? Any idea why I'm getting a /x011 at the end and not /x31
0x31 is decimal 49. 49 is ASCII for the character of '1'. Because the print statement will automatically convert any byte within ASCII range to its ASCII character, it is printing out the character '1'. Try appending 0x41 (decimal 65) which is the ASCII value for the letter A.
This is a great super beginner tutorial. Now let's talk about real-world applications. Say you have a phrase, "I love burritos!" encoded in UTF-8. How do you convert that to binary and how do you read it back and "decode" it for human consumption?
How I can convert Byets to bainnary 01 I'm trying set default blob in sqlite3 with 'executescript()' method so the photo should convert to bainnary variable.
Great work very useful and explained well. I just started programming and this is happening to me: def int2bytes(value, length): result = bytearray() for i in range(0, length): result.append(value >> (i * 8) & 0xFF) result.reverse() print(result) int2bytes(580, 2) The expected result is b'x02-x44' instead I have b'-x02D' Can you help me?
Many iot devices talk in bytes and hex strings for returned values. For example you can send multiple sensor data in single byte array and chop the data out and convert it to a more readable format like decimal at the other end.
A byte is a list of eight 0's and 1's (it does not need to be interpreted as a number encoded in binary but you can). There is a direct correspondence between those list of 8 bits and numbers 0-255 given by the binary representation of a number (base 2), for example 00000000 is 0, 00000001 is 1, and 11111111 is 255. Hexadecimal is another way of encoding numbers but it's base is 16, for example 00 is 0, 01 is 1, and ff is 255 (read Wikipedia article on hex but 0-9 is 0-9 and a-f is 10-15). It doesn't really matter from a mathematical standpoint how you write these things down because there are formulas that convert each one into the other and back again. That is a byte=a list of eight 0's and 1's = a number from 0-255 in binary = a number from 0-255 in hexadecimal = a number from 0-255 in standard base 10. All the same thing with just different notations. Some notations are just more useful in different contexts. (There are even more manifestations of a byte than this, in the loosest sense a byte (in this context) is 256 distinct symbols of one kind or another. In Java it's the numbers −128 to 127 for example lol.) So in the video each byte is represented by the two digits in hexadecimal after each "\x". They could have used eight 0's and 1's but that would have been really long for the same thing. That said, it seems like numbers between 0 and 255 would be easier to stick to for bytes though (C# does this).
Any suggestions for how once you've read in a binary file, how you would plot it? I'd like to be able to take any binary file, prompt the user if the data is 8, 16, or 32-bits big, msb/lsb endiness, and then plot every data element!
Not sure what mean. If you mean the yellow circle that shows up around the mouse cursor, that is something the video editing software (Screencast-o-matic) adds.