Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to do a hex calculation directly with bc, I already specified the scale.

echo 'scale=16;c06b1000-c06a5e78' | bc

But I still get a zero. What could be wrong?

share|improve this question
    
While not technically an answer to your question, you might want to consider moo(1) instead of bc(1). – user24323 Oct 6 '12 at 2:09
up vote 17 down vote accepted
echo 'ibase=16;C06D1000-C06A5E78' | bc
176520

if you need answer in hex too (but note that only upper case hex digits are supported as lower case ones would conflict with function and variable names, which is why you got 0 in your example (var1 - var2)):

echo 'obase=16;ibase=16;C06D1000-C06A5E78' | bc
2B188

ps. FYI scale isn't designed for conversion base. from man bc:

scale defines how some operations use digits after the decimal point.
The default value of scale is 0.
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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