User Tools

Site Tools


other:python:misc_by_jyp

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
other:python:misc_by_jyp [2023/04/27 17:52] – [Data representation] Improved jypeterother:python:misc_by_jyp [2023/04/28 16:11] – [Numerical values] Added low level array addressing jypeter
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 113: Line 116:
 '00000003 00000011' '00000003 00000011'
 </code> </code>
 +
 +  * Manipulating binary data with [[https://docs.python.org/3/library/stdtypes.html#binary-sequence-types-bytes-bytearray-memoryview|bytes, bytearray, memoryview]]
  
   * Array addressing   * Array addressing
 +    * [[https://www.geeksforgeeks.org/calculation-of-address-of-element-of-1-d-2-d-and-3-d-using-row-major-and-column-major-order/|Calculation of address of element of 1-D, 2-D, and 3-D using row-major and column-major order]]
 +      * In other words: //using indices to go from 1-D to n-Dimnensions data// 
 +    * The [[https://en.wikipedia.org/wiki/Array_(data_structure)|array]] structure
     * python/C vs Fortran...     * python/C vs Fortran...
  
Line 128: Line 136:
  
   * 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 =====
  
other/python/misc_by_jyp.txt · Last modified: 2024/11/04 15:01 by jypeter

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki