New Version of QCalc Programmer’s Calculator

share on: 
mechanic calculator
Table of Contents
Tags:   

A new Python version of the popular QCalc tool has been released in QTools 6.9.2. The new QCalc is a console application, unlike its predecessor, which was a GUI app (based on Tcl/Tk).

QCalc Programmer's Calculator in a console
QCalc console application

QCalc Features

The main selling point of the “qcalc” calculator is that it accepts expressions in the C-syntax and outputs integer results in decimal, hexadecimal, and binary formats simultaneously.

The expressions can contain all bit-wise operators (<<, >>, |, &, ^, ~) in the same precedence as C/C++. You can also use mixed decimal, hexadecimal and binary numbers. “qcalc” is also a powerful floating-point scientific calculator and supports all mathematical functions (sin(), cos(), tan(), exp(), ln(), …). Some examples of acceptable expressions are:

  • ((0xBEEF << 16) | 1280) & ~0xFF -- binary operators, mixed hex and decimal numbers
  • ($1011 << 24) | (1280 >> 8) ^ 0xFFF0 -- mixed @ref qcalc_bin "binary", dec and hex numbers
  • (1234 % 55) + 4321//33 -- remainder, integer division (note the // integer division operator)
  • pi/6 -- pi-constant, storing a value in the ans variable
  • pow(sin(ans),2) + pow(cos(ans),2) -- scientific floating-point calculations, ans-variable

64-bit Range

QCalc supports the 64-bit range and switches to 64-bit arithmetic automatically when an integer result of a computation exceeds the 32-bit range. Here are some examples of the 64-bit output:

> 0xDEADBEEF << 27
= 501427843159293952 | 0x06F5'6DF7'7800'0000
= 0b00000110'11110101'01101101'11110111'01111000'00000000'00000000'00000000
> 0xDEADBEEF << 24
= 62678480394911744 | 0x00DE'ADBE'EF00'0000
= 0b00000000'11011110'10101101'10111110'11101111'00000000'00000000'00000000
> 0xDEADBEEF << 34
! out of range
>

Downloading/Installing QCalc

QCalc has been released to the PyPi Python Package Index, so it can be installed with the following command:

pip install qcalc

QCalc is also included in the QTools collection, so it will be available after installing QP-bundle.

More Information

More information about QCalc is available in the QTools Manual online.

Discussion

Leave a Reply