GithubHelp home page GithubHelp logo

nathancarter209 / conversion Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 2 KB

This is simple code of Conversion for Binary to Decimal and Decimal to Binary.

C 100.00%
binary-to-decimal conversion decimal-to-binary math

conversion's Introduction

#Binary - Decimal ###This is a simple code to convert Binary number to Decimal number

  1. Binary
  • Use math library.
  • The code is a program that calculates the decimal equivalent of a binary number.
  • The code starts by asking for the user to enter their binary number, which is then stored in n. Next, q is set equal to n and s is set to 0.
  • Then k is initialized with 0 and while q > 0 loops through 10 iterations of calculating r=q%10;s=s+r*pow(2,k);q=q/10;k++;, The first line calculates r as the remainder after dividing q by 10.
  • The next two lines calculate s as the sum of r multiplied by 2 raised to power k and then adding it back into s so that it can be used later on in calculations.
  • Lastly, q decreases from 10 down to 1 before looping back up again because there are still more iterations left until we reach zero (0).
  1. Decimal
  • Use math library.
  • The code starts by asking the user to enter a decimal number.
  • The code then loops through the binary digits of that number, which are in reverse order.
  • It starts with 0 and increments it until it reaches k, where it stops.
  • Then, the code prints out the binary number and returns 0.
  • The code is a simple program that asks the user to enter a decimal number and then outputs the binary equivalent of the input.

conversion's People

Contributors

nathancarter209 avatar

Watchers

 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.