1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Need some ideas on making a Bin/Dec/Hex converter.

Discussion in 'C' started by Mythion, Sep 29, 2006.

  1. Mythion

    Mythion New Member

    Joined:
    Sep 29, 2006
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Hi, i am new in Go4Expert and i need some ideas on making a Bin/Dec/Hex converter(in C++)...
    the main problems are:
    1. when accessing an intger it's not possible to go over every digit it has like in arrays,
    you can have a char array:
    char arr[10]="Hello";
    and the array is really "H", "e", "l", "l", "o"...
    2. when you declare a intger array:
    int arr[10];
    you can't input a number such as "10011011" and the int array will be "1", "0", "0", "1", "..." and so on, to do so you can do a For loop, but then you have to input each number separately and this becomes a huge probelm with binary numbers such as "100101100011110111" and longer...

    there are more problems but if one of these two are not solved there is no point going forward...

    thanks in advance.
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,283
    Likes Received:
    364
    Trophy Points:
    83
    Welcome to G4EF.

    Regarding your problem you can do is get the binary number in the character array. Something like
    Code:
    char arr[10]="10011011"
    and then typecast it to the array of integers or whatever you wish to do with like integers is possible.
     
  3. Mythion

    Mythion New Member

    Joined:
    Sep 29, 2006
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Good idea, i never thought of typecasting arrays...
     

Share This Page