2

Any software that can quickly do some basic calculations like binary addition, hexadecimal addition etc. in the below mentioned format?

I was using a calculator in Windows, Kalkulon, that could simply add two binary numbers like:

0b11 + 0b01 
0xAB + 0xCD

I am unable to find an equivalent in Linux. I am looking for a command line variant.

I tested R, Python, gcalccmd. But all of them require some complicated syntaxes for so easy calculations.

1
  • which part of python do you think complex? It can do 0b11 + 0xAB + 123 + 0777 without problem
    – phuclv
    Aug 16, 2018 at 3:22

2 Answers 2

1

What you need is already installed:

$> echo 'obase=16; ibase=16; AB+CD' | bc
178
$> echo "obase=2; ibase=2; 11+01" | bc
100

For easier use, you could set up aliases (or use shell scripts):

alias hexcalc='function _hexcalc(){ echo "obase=16; ibase=16; $1"|bc; };_hexcalc'
alias bincalc='function _bincalc(){ echo "obase=2; ibase=2; $1"|bc; };_bincalc'

Then, easily use them:

$> hexcalc AB+CD
178
$> bincalc 11+01
100

Of course, if it's not there, you will need to install the bc package – which is available in the standard repositories of all Linux distributions I know.

2
  • the calculations are the mixture of binary and hex.. And since I needed to copy it from a C code, it would be better to maintain the syntax of 0b and 0x Apr 27, 2017 at 18:13
  • Understood. But based on my little guide, you could write up a shell script taking care for that, providing both arguments are always of the same type (i.e. either both hex or both bin), generating the required statement and invoking the corresponding command (after having stripped the prefix and uppercased the remains). Unless someone else comes up with a better solution, that is :)
    – Izzy
    Apr 27, 2017 at 18:44
0

I found something that would suffice my need with the syntaxes. I could do it on www.wolframalpha.com ( also mixing inputs such as 0b11 + 0x34 ) . However, a dedicated package installed on the computer would be great. So, still waiting for more answers.

Edit : The package genius is awesome and has lots of functions. I didnt know about it and find it the best calculator for scientific functions till now.

sudo apt-get install genius

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.