LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Blogs
User Name
Password

Notices


Old

Convert numeral systems (dec <-> bin <-> hex <-> oct)

Posted 12-10-2013 at 03:41 AM by druuna
Updated 01-31-2014 at 03:24 AM by druuna

Converting from one numeral system to another can be done using the bc command.

Here are a few examples in the form of functions:

# -------------------------------------------------------------------------- #
# - Decimal to ....
# -------------------------------------------------------------------------- #
  • Binary
PHP Code:
# Convert decimal to binary
function decToBin() {
  echo 
"obase=2;$1" bc

Code:
$ decToBin 19
10011
...
LQ Veteran
Posted in General
Views 3775 Comments 0 druuna is offline

  



All times are GMT -5. The time now is 11:57 PM.

Main Menu
Advertisement
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration