File: atom.py

package info (click to toggle)
actor-framework 0.17.6-3.2
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 9,008 kB
  • sloc: cpp: 77,684; sh: 674; python: 309; makefile: 13
file content (39 lines) | stat: -rwxr-xr-x 1,004 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env python

from __future__ import print_function
import sys

# decodes 6bit characters to ASCII
DECODING_TABLE = ' 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz'

def atom_read(x):
    result = ''
    read_chars = ((x & 0xF000000000000000) >> 60) == 0xF
    mask = 0x0FC0000000000000
    bitshift = 54
    while bitshift >= 0:

        if read_chars:
            result += DECODING_TABLE[(x & mask) >> bitshift]
        elif ((x & mask) >> bitshift) == 0xF:
            read_chars = True

        bitshift -= 6
        mask = mask >> 6
    return result

if __name__ == '__main__':
    if len(sys.argv) != 2:
        print('*** Usage: atom.py <atom_val>')
        sys.exit(-1)
    try:
        s = sys.argv[1]
        if s.startswith('0x'):
            val = int(s, 16)
        else:
            val = int(s)
        print(atom_read(val))
    except ValueError:
        print('Not a number:', sys.argv[1])
        print('*** Usage: atom.py <atom_val>')
        sys.exit(-2)