Skip to main content

CLI tool for practicing two's complement representation of signed integers

Project description

Two's Complement Practice Tool

This is a command-line tool for practicing and reviewing two's complement representation of signed integers.

Developed for CS2210 (Computer Organization) at the University of Vermont by Clayton Cafiero.


Installation

pip install twos-complement-practice

Usage

After installing:

$ twos-practice

You will be prompted to choose a bit width (e.g., 4, 8, etc.). The program will then randomly select from three activity types:

  • Additive inverse: Given a bitstring, provide the additive inverse in two's complement form.
  • Decimal to bitstring: Convert a signed decimal integer to two's complement binary.
  • Bitstring to decimal: Convert a two's complement binary string to a decimal integer.

You can exit at any prompt by typing q.

At the end, you'll get a summary of your performance and a list of any incorrect responses.

Running in Python or your IDE

You can also import and run the tool interactively:

import twos_complement_practice as tcp
tcp.run()

Utility functions

The module also exposes two utility functions, bin2dec and dec2bin.

  • bin2dec converts a bitstring to an integer representation (a Python int).
  • int2dec converts a Python integer to a binary bitstring (this requires a second argument, an int representing the number of bits to use).

Educational goals

This tool is designed to:

  • reinforce understanding of signed binary number representation,
  • develop fluency with two's complement conversions, and
  • provide low-stakes, interactive feedback for learners.

License

This project is licensed under the terms of the GNU General Public License v3.0.

You are free to use, modify, and distribute this software under the conditions specified in the license.

© 2025 Clayton Cafiero
For inquiries, contact cbcafier@uvm.edu


Dependencies

  • colorama: for cross-platform colored terminal output.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

twos_complement_practice-1.0.3.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

twos_complement_practice-1.0.3-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file twos_complement_practice-1.0.3.tar.gz.

File metadata

File hashes

Hashes for twos_complement_practice-1.0.3.tar.gz
Algorithm Hash digest
SHA256 ef71cbb58a9f809d4401d02a265199aa03055ebd0c2fcddc46b7f116ba0e61c9
MD5 ec7819438f57467c559059ad46664556
BLAKE2b-256 b11d4dbc6a8b7abc2b15ad062911a1475f92216500add29b281e1a8977f49399

See more details on using hashes here.

File details

Details for the file twos_complement_practice-1.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for twos_complement_practice-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 229ba9b448ca889d0934751f1b8d34265d9c81b5a0bfaf86bee653a4cf709b9f
MD5 f4bfba0bbd3bc70702ee670873162f15
BLAKE2b-256 86c8e90c1c30e4d68bd28f5c6289a7b1d8993155dede22e67e2fe0d864139ce5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page