Skip to main content

Xalc is a hexadecimal calculator for embedded systems programmers, implemented as a pre-processor for Python expressions, with a console interface based on IPython.

Features:

  • Mixed calculations with hex, decimal, binary and binary prefix literals

  • Support for undecorated hex literals. Ambiguous literals can be forced to hex by either prefixing or suffixing with ‘x’.

  • Display in hex, decimal, binary (with bit position ruler) and binary prefixes (sizes)

  • Simple bit mask construction

  • Bit field extraction operator

  • From IPython: Support for arbitrary Python expressions (minus the ones that conflict with the pre-processed syntax), command history, access to previous results with _* variables, etc.

The following “screenshot” demonstrates some of the features of Xalc. The real program displays the different bases in different colors, if your console supports that:

$ xalc
In [1]: deadbeef
0xdeadbeef
Out[1]:
3735928559    │  28─╮ 24─╮ 20─╮ 16─╮ 12─╮  8─╮  4─╮  0─╮
0xdeadbeef    │  1101 1110 1010 1101 1011 1110 1110 1111
3 Gi + 490 Mi + 879 Ki + 751

In [2]: deadbeef $ m5t13
0xdeadbeef >> 5 & ((0x3fe0) >> 5)
Out[2]:
 503           │  28─╮ 24─╮ 20─╮ 16─╮ 12─╮  8─╮  4─╮  0─╮
 0x000001f7    │  0000 0000 0000 0000 0000 0001 1111 0111

In [3]: _ ^ cafe
_ ^ 0xcafe
Out[3]:
 51977         │  28─╮ 24─╮ 20─╮ 16─╮ 12─╮  8─╮  4─╮  0─╮
 0x0000cb09    │  0000 0000 0000 0000 1100 1011 0000 1001
 50 Ki + 777

In [4]: 7f000000 - 35000000x
0x7f000000 - 0x35000000
Out[4]:
 1241513984    │  28─╮ 24─╮ 20─╮ 16─╮ 12─╮  8─╮  4─╮  0─╮
 0x4a000000    │  0100 1010 0000 0000 0000 0000 0000 0000
 1 Gi + 160 Mi

In [5]: m2p0_5_8t9_29_31t31
(0x3|0x20|0x300|0x20000000|0x80000000)
Out[5]:
 2684355363    │  28─╮ 24─╮ 20─╮ 16─╮ 12─╮  8─╮  4─╮  0─╮
 0xa0000323    │  1010 0000 0000 0000 0000 0011 0010 0011
 2 Gi + 512 Mi + 803

In [6]: 2g | m12
0x80000000 | (0x1000)
Out[6]:
 2147487744    │  28─╮ 24─╮ 20─╮ 16─╮ 12─╮  8─╮  4─╮  0─╮
 0x80001000    │  1000 0000 0000 0000 0001 0000 0000 0000
 2 Gi + 4 Ki

In [7]: -45
-45
Out[7]:
 -45           │  28─╮ 24─╮ 20─╮ 16─╮ 12─╮  8─╮  4─╮  0─╮
 0xffffffd3    │  1111 1111 1111 1111 1111 1111 1101 0011

Install with pip:

pip install --upgrade xalc

Or by cloning the git repo and running:

python setup.py install

Run xalc after installation.

Release files for xalc 0.6.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for xalc 0.6.0
File Size Uploaded
xalc-0.6.0.tar.gz 5.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for xalc 0.6.0
File Interpreter ABI Platform
xalc-0.6.0-py2-none-any.whl Python 2 none any Details

Total release size: 12.4 kB

Release files / xalc-0.6.0.tar.gz

Download URL xalc-0.6.0.tar.gz
Size 5.5 kB
Tags Source
SHA-256 checksum
How to use checksums
917d00f003ee312d00ef3b139ba09b9cb06c9e4c3955d3d3af54ad0c6de818de
BLAKE2b-256 checksum
How to use checksums
d2e11d7f3ffe3cb8e79ae0819557f3b152d5b5694c9bedb38f9a5713a7b69241
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.7.0 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.2+

Release files / xalc-0.6.0-py2-none-any.whl

Download URL xalc-0.6.0-py2-none-any.whl
Size 6.9 kB
Tags Python 2
SHA-256 checksum
How to use checksums
ce648a692db72444b56b9a8752505c1a8e67db70dd67efa290b398906bd85937
BLAKE2b-256 checksum
How to use checksums
3ce15b52cbe2805a38dcbd56ee826215f394a9d69eb662651497b9cb1ccdedde
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.7.0 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.2+

Release history Release notifications | RSS feed

This release

0.6.0 This release

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page