Sungju's Slow Life

Personal journal


Use hexadecimal in ‘bc’

‘bc’ is really cool application in Linux/Unix. it provides lots of convenient functions without launching GUI calculator.

One thing sometimes necessary is a conversion for the calculation. Mostly converting hexadecimal and decimal.

If you want to use hexadecimal for the input, you can use ‘ibase=16’ and below value will be all treated as 16base.

$ bc
ibase=16
EA8-E98
16
ea8-e98
0

http://pagead2.googlesyndication.com/pagead/show_ads.js

One thing careful is don’t use lowercase for the hexadecimal characters. All needs to be upper case. If you want to put the results in hexadecimal as well, you can use ‘obase=16’.

$ bc
obase=16
ibase=16
EA8-E98
10
ea8-e98
0

You shouldn’t use obase=16 after ibase=16 which will treat 16 as hexadecimal value 16 (22 in decimal).



Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

About Me

A software engineer who loves any technologies that makes life easier. That’s why I love Linux and Mac at the same time.

Newsletter

%d bloggers like this: