This shows you the differences between two versions of the page.
Both sides previous revision Previous revision | Next revision Both sides next revision | ||
other:python:misc_by_jyp [2023/04/27 15:52] jypeter [Data representation] Improved |
other:python:misc_by_jyp [2023/04/28 13:55] jypeter [Data representation] Improved, started a Strings section |
||
---|---|---|---|
Line 35: | Line 35: | ||
A few notes for a future section or page about about //data representation// (bits and bytes) on disk and in memory, vs //data format// | A few notes for a future section or page about about //data representation// (bits and bytes) on disk and in memory, vs //data format// | ||
+ | |||
+ | |||
+ | ==== Numerical values ==== | ||
* Binary data representation of some numbers: | * Binary data representation of some numbers: | ||
Line 128: | Line 131: | ||
* Misc : ''md5sum'' | * Misc : ''md5sum'' | ||
+ | |||
+ | ==== Strings ==== | ||
+ | |||
+ | * Encoding, [[https://en.wikipedia.org/wiki/ASCII|ASCII]], [[https://en.wikipedia.org/wiki/Unicode|unicode]], [[https://en.wikipedia.org/wiki/UTF-8|UTF-8]], ... | ||
+ | |||
+ | * Getting the binary representation of a string | ||
+ | * <code>>>> test_string = 'A B 0 1 à µ' | ||
+ | >>> type(test_string) | ||
+ | <class 'str'> | ||
+ | >>> len(test_string) | ||
+ | 11 | ||
+ | >>> test_string_bin = test_string.encode('utf-8') | ||
+ | >>> test_string_bin | ||
+ | b'A B 0 1 \xc3\xa0 \xc2\xb5' | ||
+ | >>> type(test_string_bin) | ||
+ | <class 'bytes'> | ||
+ | >>> len(test_string_bin) | ||
+ | 13 | ||
+ | >>> test_string_bin.hex('-') | ||
+ | '41-20-42-20-30-20-31-20-c3-a0-20-c2-b5' | ||
+ | </code> | ||
+ | |||
===== Checking if a file/directory is writable by the current user ===== | ===== Checking if a file/directory is writable by the current user ===== | ||