• Stars
    star
    538
  • Rank 82,538 (Top 2 %)
  • Language
    C
  • License
    GNU General Publi...
  • Created almost 4 years ago
  • Updated 7 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Terminal calculator made for programmers working with multiple number representations, sizes, and overall close to the bits

Programmer calculator

The programmer calculator is a simple terminal tool designed to give maximum efficiency and flexibility to the programmer working with:

  • binary, hexadecimal and decimal representations at the same time
  • bitwise operations
  • various operand sizes (16bits, 32bits, 8bits, etc)

and who likes:

  • a clear, simple and customizable interface
  • open source software
  • terminal/cli tools

Screen The above picture depicts pcalc without colors, and below is an example of pcalc with colors enabled (--colors) (which change depending on the terminal profile colors) Screen-Colored

Making of

The idea was born while developing a Nintendo Gameboy Emulator. Romes - the pitcher - found that the tools given online were clunky and did not allow for "nice multitasking"

With the constant need to visualize and manipulate bits, it became evident that a better solution had to come to life

Installation

Homebrew

Install from the homebrew official packages

brew install pcalc

Arch Based Distros

Install from AUR

yay -S programmer-calculator

Building from Source (alternative)

Prerequisites:

To build from source you need gcc, ncurses, and the source files. If you don't have ncurses, please install it (i.e. with your system's package manager) first. (To install ncurses in Debian based distros run sudo apt-get install libncurses5-dev libncursesw5-dev)

Building:

First, clone the repository and change directory to it

git clone https://github.com/alt-romes/programmer-calculator ; cd programmer-calculator

Then, compile the code into an executable file and install it (installs in /usr/local/bin)

sudo make install

Conversely, if you ever want to uninstall, you can run:

sudo make uninstall

Updating

Either re-build from source, or, using brew do

brew update

followed by

brew upgrade pcalc

Running

Just run the programmer calculator program

pcalc

Features

Usage

There are various ways to insert values/operators, see the example 2 + 2 below:

  • 2, followed by +, followed by 2
  • 2, followed by +2
  • 2+, followed by 2
  • 2+2 (or i.e. 2 + 2)

Inline Math

Operator precedence and parenthesis for grouping is used.

2+2*3 evaluates to 8 and (2+2)*3 evaluates to 12

Hex + Binary + Decimal

All three number representations are available at the same time, you can insert 0xff + 0b101101 - 5 directly onto the calculator

Operand Size

By default, 64 bits are used for arithmetic, however, when working with bits, quite often we want to work with less. With this calculator you can change the amount of bits used. the number displayed will be unsigned

To use 16 bits instead, type 16bit (bits will also work)

To use 8 bits, type 8bit

To use 0 < n <= 64 bits, type nbit

Customizing Interface

While running the calculator, you can type what you see for it to appear/disappear:

history to toggle the history decimal to toggle the decimal representation binary to toggle the binary representation hex to toggle the hexadecimal representation operation to toggle the operation display

Additionally, the interface colors can be toggled on and off.

To set a default interface, define an alias for the program with the desired hidden options

alias pcalc='pcalc -ibxdosn'

i: history, b: binary, x: hex, d: decimal, o: operation, s: symbols, n: no colors

You can also use the long options to hide parts: --history, --decimal, etc.

Operations

ADD  +    SUB  -    MUL  *    DIV  /
MOD  %    AND  &    OR   |    NOR  $
XOR  ^    NOT  ~    SL   <    SR   >
RL   :    RR   ;    2's  _    SE   @
  • ADD: a + b arithmetic addition
  • SUB: a - b arithmetic subtraction
  • MUL: a * b arithmetic multiplication
  • DIV: a / b arithmetic integer division
  • MOD: a % b modulus from the division
  • AND: a & b bit-wise AND operation
  • OR : a | b bit-wise OR operation
  • NOR: a $ b bit-wise NOR operation : opposite of OR
  • XOR: a ^ b bit-wise XOR operation : exclusive OR
  • NOT: ~a bit-wise NOT operation : change all bits of a, 0's into 1's and 1's into 0's
  • SL : a < b bit-wise SHIFT-LEFT operation : shift a left b number of times
  • SR : a > b bit-wise SHIFT-RIGHT operation : shift a right b number of times
  • RL : a : b bit-wise ROTATE-LEFT operation : rotate a left b number of times
  • RR : a ; b bit-wise ROTATE-RIGHT operation : rotate a right b number of times
  • 2's: _a 2's complement operation : 2's complement of a (usually is the symmetric of a)
  • SE : @a swap endianness : swap the byte order of a (uses the number of bits set by bit to determine the amount of bits swapped)

Contributing

Please reference Contributing


example usage in iterm panel

Panels

More Repositories

1

hegg

Fast equality saturation in Haskell
Haskell
75
star
2

ghengin

Ghengin: A vulkan-based, shader-centric, type-heavy, Haskell game engine
Haskell
42
star
3

reference-counting

Reference counting with linear types
Haskell
27
star
4

calculator-c-parser

A simple implementation of a parser and its use to calculate simple mathematical expressions
C
16
star
5

chip8-emulator-for-gameboy

A chip8 emulator made in gameboy assembly for the gameboy
Assembly
14
star
6

haskell-x-swift-project-steps

A step-by-step Haskell x Swift project where the commits match the steps described in the accompanying blog post
Swift
13
star
7

llvm-c-search

Terminal interface to search the LLVM-C API
Go
12
star
8

minblog

a minimal blog platform using github for hosting content and page
Vue
11
star
9

gameboyemulator

simple gameboy emulator
C
8
star
10

mermaid-hs

A Haskell library for parsing mermaid diagrams
Haskell
8
star
11

slfl

The SILI synthesiser - synthesis of linear functional programs
Haskell
7
star
12

haskell-swift

Haskell x Swift interoperability libraries and tools
Haskell
7
star
13

albumsofthemonth

generate a page to display albums. add albums with an npm command. hosted on github
CSS
5
star
14

onory

High-level language embedded in Haskell for specifying distributed algorithms/systems
Haskell
5
star
15

hackathon-2022

bora
JavaScript
5
star
16

ghc-linear-synthesis-plugin

A GHC plugin for synthesizing Haskell programs from Linear Types using bottom-up proof search in linear logic with focusing
Haskell
4
star
17

c-compiler

Why am I writing another C to LLVM compiler
C
3
star
18

minecraft-dhall

Draft: Minecraft mod development with Dhall
Haskell
2
star
19

social-index-search-engine

FCT Hackathon 2023 Project
JavaScript
2
star
20

operating-system

C
2
star
21

simplest-godot-dialogues

Simple dialogue controller and example scene
GDScript
2
star
22

linear-core

My master thesis on typechecking linearity in GHC Core, by understanding semantic linearity in the presence of call-by-need evaluation
Haskell
2
star
23

Operator

IPCA Game Jam submission
Python
1
star
24

haskell-ui

Haskell
1
star
25

cabal-check-det

Developer script to compare objects produced by GHC for a Cabal package
Shell
1
star
26

advent-of-code-2021

LLVM
1
star
27

homebrew-pcalc

homebrew tap for the programmer calculator
Ruby
1
star
28

.vim

minimalist and modern vim configuration with sane settings, handwritten statusline and tabline, small custom plugins, and few external plugins
Vim Script
1
star
29

dotfiles

C
1
star
30

ludum-dare-49

C++
1
star
31

project-euler

Attempts at Project Euler challenges
Haskell
1
star
32

generating-data-for-a-db-project

A simulation of a game to generate data for a project, and other data scraping samples
Python
1
star
33

ldjam45

open sourced submission for the Ludum Dare 45 Game Jam
HTML
1
star
34

asd-babel-gen

For ASD: Automatically generate entire Babel projects from pseudo-code :)
Haskell
1
star
35

papers

TeX
1
star
36

langjam-cdc

A very simple language that when interpreted displays in a graphical window the composition done in the main function (langjam submission)
Haskell
1
star
37

madjam-2021

Mad Game Jam 2021 Submission [Memories]
GDScript
1
star
38

bots

Python
1
star
39

control

setting up home, with extra steps
CSS
1
star
40

pushups-commander

https://alt-romes.github.io/pushups-commander/
Haskell
1
star
41

ggj21

Global Game Jam 2021 submission!
JavaScript
1
star
42

cob-hs

Haskell
1
star