Coder Social home page Coder Social logo

dec2bin's Introduction

dec2bin

Decimal to binary command-line conversion utility.

Usage

Internally, numbers are represented as mpz_t, which is GNU GMP's arbitrary- precision integral data type. Numbers of any size may therefore be represented, so, theoretically speaking, the limit is your computer's memory, and in more practical terms, the limit is how long you're willing to sit in front of your computer waiting for the result.

Examples

For simple conversions you can simply pass in your desired inputs.

$ ./dec2bin 845777
11001110011111010001

Should you wish to configure the output to look a little nicer, or at least make it easier to read, the current options available are --pretty-print and --group-size. The former pads the output to be even groups of n, where n is the group size, and the latter actually specifies a custom group size.

If you specify --pretty-print without setting a group size, the program will use the default, which is 4. If you specify a group size without actually requesting for the program to pretty-print your output, the program will disregard your request and print the output as if you had specified no options at all. I might change this in the future to allow the --group-size option to imply --pretty-print, but at the moment the program does exactly what you explicitly tell it to; nothing more, nothing less. I mean this literally, as specifying a group size without specifying the --pretty-print option will set the group size, but will not route the output through the subroutine that would use it.

Here is an example of a custom group size setting with a large input integer.

$ ./dec2bin --pretty-print --group-size 8 683543568763521656876541231
00000010 00110101 01101001 11111011 00011100 10110010 01000110 00110001 11110110 10110001 10100101 00101111

Building

The program uses the GNU Multiple Precision library to handle inputs of any size, so this is the only real requirement. Besides that, the application is written in C17-conforming standard C, so as long as you have a conforming C compiler you should have no problem building the application, aforementioned pre-requisites notwithstanding.

The makefile is currently set to my default options, so you cannot currently override any settings via the command-line. I apologize for this, but you may modify the makefile to allow for this, or you may simply edit it as you see fit.

Pull requests are welcome, and feel free to drop me a line if you have any problems, questions, concerns, bug reports, etc.

dec2bin's People

Contributors

jflopezfernandez avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.