Skip to content
/ pcalc Public
forked from vapier/pcalc

command line util for doing hex/dec/oct/bin math quickly

License

Notifications You must be signed in to change notification settings

cstatic/pcalc

 
 

Repository files navigation

                                PCALC

Programmer's calculator,  command line utility. 

There was always a loophole when it came to a need to covert between
hexadecimal / decimal / octal / binary.

Especially if it involved an operation like 0x1234 + 0x20
It took a lot of hard work, and mostly a good pocket calculator.

Main features:

     o Full math parser, parentheses, add, sub, mult, div, exponential
     o Automatic conversion between HEX DEC OCT BIN numbers
     o Mixing different bases in one expression
     o Definable variables
     o Math constants (E PI ...)
     o Built in math functions (sin/cos/sqrt ...)

Specification:

 Number specification:

    0x1234              hexadecimal
    0c1234              octal
    0o1234              octal
    0y0101              binary
    123456              decimal

 Built in functions:

    sin             mathematical sinus
    cos             mathematical cos
    atan            mathematical atan
    log             mathematical log
    log10           mathematical log10
    exp             mathematical exp
    sqrt            mathematical sqrt
    int             mathematical int
    abs             mathematical abs
    f2c             converting temperature-> fahrenheit to celsius
    c2f             converting temperature-> celsius to fahrenheit
    in2mm           converting length-> inches to millimeter
    mm2in           converting length-> millimeter to inches
    po2kg           converting mass-> pounds to kilogram
    kg2po           converting mass-> kilogram to pounds

 Built in controls:

    echo            echo to the screen
   _echo            echo to the screen, no new line
    date            echo to the screen, expanding date variables 
   store            store variable to file
   restore          restore viable from file

 Built in variables:

    DEBUG           for debug 0=off 1=on
    DEC             controlling number display 0=default 1=dec 2=hex 3=bin 4=oct

Operator priorities:

     LOW    '='         assignment
            or          binary or
            and         binary and
            '>' '<'     binary left/right shift
            '+' '-'     addition/subtraction
            '*' '/' '%' multiply/divide/modulus
            '-'         unary minus
     HIGH   '^'         exponentiation

Syntax:

	pcalc  var
	pcalc  expr
	pcalc  number
	pcalc  var = number
	pcalc  builtin expr
	pcalc  builtin ( expr )
	pcalc  date "string"
	pcalc  echo "string"
	pcalc  _echo "string"
	pcalc  store    var
	pcalc  store    var to  "file"
	pcalc  restore  var
	pcalc  restore  var from "file"

The result is output in 3 parts: 

    DEC number	     HEX number	     BIN number

      20              0x14            0y10100

If the number is out of range from the HEX and BIN numbers, the
truncated numbers are displayed.

Examples:

(see also the ./ptest directory)
--------------------------------------------------------------------------

c:>pcalc 0x300

	 768         0x300       0y1100000000

--------------------------------------------------------------------------

c:>pcalc '0x300 + 3 * 3'

	 777             0x309           0y1100001001

Note: shell expansion on the '*' char required the single quote

--------------------------------------------------------------------------

c:>pcalc sqrt 2

	 1.4142136   0x1         0y1

--------------------------------------------------------------------------

c:>pcalc sqrt(2)

    1.4142136   0x1         0y1

--------------------------------------------------------------------------

c:>pcalc 0x12 or 23

    23          0x17        0y10111

--------------------------------------------------------------------------

To execute a calculation script from a file, precede the file name with the
character '@'.

Example:

pcalc @pcalc.001

Dirty:

This project was constructed in a 'quick and dirty' schedule, please
forgive missing parts etc ...

Feedback:

Please send email about updates/ports/suggestions to

https://github.com/vapier/pcalc/issues

About

command line util for doing hex/dec/oct/bin math quickly

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C 56.8%
  • Lex 23.9%
  • Yacc 15.0%
  • Makefile 4.3%