spc_spectra.utils

Utility functions

 1"""
 2Utility functions
 3"""
 4# --- Imports
 5
 6# Standard library
 7from __future__ import division, absolute_import, unicode_literals, print_function
 8
 9
10# --- Functions
11
12def flag_bits(n):
13    """
14    Return the bits of a byte as a boolean array.
15
16    Arguments
17    ---------
18    n (charater):
19        8-bit character passed
20
21    Returns
22    -------
23    list (bool):
24        boolean list representing the bits in the byte
25        (big endian) ['most sig bit', ... , 'least sig bit' ]
26
27    Example
28    -------
29    >>> flag_bits('A') # ASCII 65, Binary: 01000001
30    [False, True, False, False, False, False, False, True]
31    """
32    return [x == '1' for x in list('{0:08b}'.format(ord(n)))]
def flag_bits(n):
13def flag_bits(n):
14    """
15    Return the bits of a byte as a boolean array.
16
17    Arguments
18    ---------
19    n (charater):
20        8-bit character passed
21
22    Returns
23    -------
24    list (bool):
25        boolean list representing the bits in the byte
26        (big endian) ['most sig bit', ... , 'least sig bit' ]
27
28    Example
29    -------
30    >>> flag_bits('A') # ASCII 65, Binary: 01000001
31    [False, True, False, False, False, False, False, True]
32    """
33    return [x == '1' for x in list('{0:08b}'.format(ord(n)))]

Return the bits of a byte as a boolean array.

Arguments

n (charater): 8-bit character passed

Returns

list (bool): boolean list representing the bits in the byte (big endian) ['most sig bit', ... , 'least sig bit' ]

Example

>>> flag_bits('A') # ASCII 65, Binary: 01000001
[False, True, False, False, False, False, False, True]