Specifing a particular number in a string

This is a discussion on Specifing a particular number in a string within the C++ Programming forums, part of the General Programming Boards category; I am new at this!!! I am trying to write a program that converts binary to decimal. My thought is ...

  1. #1
    Registered User
    Join Date
    Dec 2002
    Posts
    9

    Question Specifying a particular number in a string

    I am new at this!!!


    I am trying to write a program that converts binary to decimal. My thought is to manipulate the power of 2 with a counter starting at zero. Then use the power function to get the power of 2. Each time that answer needs to be multiplied by a particular number in the binary number. How do I specify that number.?

    ls
    Last edited by Lyanette; 12-29-2002 at 10:16 PM.

  2. #2
    Registered User
    Join Date
    Nov 2002
    Posts
    491
    How are you storying your number?

    cout << myint << endl;

    Doesn't work?

    If your number is stored in a string, you can just use things like strtol().

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    Assuming you've read the binary number in as a string called num, use:
    Code:
    num[0] - '0'  //to get the first binary digit
    num[1] - '0'  //to get the second binary digit
    num[2] - '0'  //to get the third binary digit
    and so on.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. xor linked list
    By adramalech in forum C Programming
    Replies: 23
    Last Post: 10-14-2008, 10:13 AM
  2. adding a number to a number
    By bigmac(rexdale) in forum C Programming
    Replies: 11
    Last Post: 10-24-2007, 12:56 PM
  3. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 02:23 PM
  4. ........ed off at functions
    By Klinerr1 in forum C++ Programming
    Replies: 8
    Last Post: 07-29-2002, 09:37 PM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21