Thread: Binary based input

  1. #1
    Registered User
    Join Date
    Sep 2004
    Posts
    18

    Binary based input

    Is there a way to enter a binary number and print its decimal equivalent.

  2. #2
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    If you mean is there a way in the C standard library, no. But it wouldn't be a chore to write one.

  3. #3
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    int main(void)
    {
        char buff[16];
    	int number;
    
    	fgets(buff,16,stdin);
    	number = strtol(buff,0,2);
    
    	printf("Decimal value is %d\n",number);
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. fscanf in different functions for the same file
    By bchan90 in forum C Programming
    Replies: 5
    Last Post: 12-03-2008, 09:31 PM
  2. Printing Length of Input and the Limited Input
    By dnguyen1022 in forum C Programming
    Replies: 33
    Last Post: 11-29-2008, 04:13 PM
  3. running shell functions based on user input.
    By System_159 in forum Linux Programming
    Replies: 14
    Last Post: 10-12-2007, 07:19 PM
  4. Tutorial review
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 03-22-2004, 09:40 PM
  5. binary to decimal
    By miryellis in forum C Programming
    Replies: 7
    Last Post: 03-14-2004, 08:35 PM