Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

A number base converter in C

License

NotificationsYou must be signed in to change notification settings

chiayolin/nbc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status

The program,nbc, stands for Number Base Converter.nbc is an open source multi-platforms number baseconverter written in C. You can usenbc to convert between binary, octal, decimal, and hexadecimal number. Theprogram itself also provides a powerful interactive mode, as well as command line options.

Installing

Linux and Mac OS X

  1. Open your terminal
  2. git clone http://github.com/chiayolin/nbc
  3. cd /path/to/nbc
  4. ./install

Windows

  1. Install Linux :-)
  2. git clone http://github.com/chiayolin/nbc
  3. cd /path/to/nbc
  4. ./install

Usage

###Command Linenbc [ -h | -m | -f ] [ -i <in base>] [ -o <out base>] [ <value> ]

Here is a list of available options:-h-m-f-i-o

OptionsDescriptions
-hprint program's information, such as license, author, and etc.
-fforce program enther the interactive mode.
-i <base>set input number base, <base> is required.
-o <base>set output number base, <base> is required.
<value>input number value, this value can not be empty.

Here are four different in/out bases, and each base has three different form.

b,bin,binary

o,oct,octal

d,dec,decimal

h,hex,hexadecimal

Arguments-i and-o expect a number base after, and both arguments need to be used at the same time. However,the<value> can not be empty. For example, when you want to convert a decimal number332000 to a binarynumber, all you need is enter:nbc -i dec -o bin 332000 into the termianl.

$ nbc -i dec -o bin 332000

Output:

1010001000011100000

Okay, so now if we want to convert a hexadecimal numberbbb6ae to a decimal number, then you will need to enternbc -i hex -o dec bbb6ae into the termianl. However, like what it says above, every number base has threedifferent forms. Therefore you can either usenbc -i h -o d bbb6ae,nbc -i hexadecimal -o decimal bbb6ae, orany liget forms have shown above. This is what it might looks like on the terminal:

$ nbc -i hex -o dec bbb6ad

Output:

12301997

A shortcut to do it:

$ nbc -i h -o d bbb6ad

Output looks the same:

12301997

Well, there is a long way to do it as well:

nbc -i hexadecimal -o decimal bbb6ae

You will get the same right output:

12301998

###Interactive Mode

The program provides a powerful interactive mode, which makes the number base conversion much easier. You can eitherenter by just runing the commandnbc, or with the-i argument,nbc -i.

When you get into the interactive mode, you will see a prompt like this:

type `help` for help>

You can use the commandhelp for help.

type `help` for help> help (Press RETURN)

Then you will get a list of available commands. However, every command is defined internally. Usehelp COMMAND tofind out more about the functionCOMMAND. For example, I want to know more about the commandset, then I willtype:

> help set (Press RETURN)

Output:

set - set input/output base.usage: set [options [values]]options:   -i, input   <base>   -o, output  <base>values:   bin, oct, dec, hex

Now you get the idea, try every command withhelp if you want.

Okay, so now let's talk about the main function ofnbc, convert number bases. Let's say you want to convert ahexdecimal numberbea to binary. Then you would want use theset command to set input base to hexadecimal, andoutput base to binary. Here is one way to do it:

> set input hex (Press RETURN)> set output bin (Press RETURN)

And of course, you can replaceinput with-i andoutput with-o:

> set -i hex (Press RETURN)> set -o bin (Press RETURN)

Available number bases can be found on the above section. You can always use thehelp command to get moreinformation about every command.

Now you are all set, so just simply enter:

> bea

Output:

101111101010

Done!!! 🎉

License

Copyright (C) 2014 Chiayo Linchiayo.lin@gmail.com

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General PublicLicense as published by the Free Software Foundation, either version 3 of the License, or any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the impliedwarranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for moredetails.You should have received a copy of the GNU General Public License along with this program. If not, seehttp://www.gnu.org/licenses/.


[8]ページ先頭

©2009-2025 Movatter.jp