Thread: Help with Error - Binary to Character Converter

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Apr 2004
    Posts
    8

    Help with Error - Binary to Character Converter

    Hi. I wrote a binary to character converter program but I have a problem - after I type in the binary (e.g. 01000001) the program stops with an error. I ran it in win XP and linux but both give error.

    The errors:
    XP:

    F:\>bin2char-0.1
    Enter string to convert : 01000001

    This application has requested the Runtime to terminate it in an unusual way.
    Please contact the application's support team for more information.


    and linux:

    [dvldrmmr@myhost /]# ./bin2char-0.1
    Enter string to convert : 01000001
    Aborted


    Any ideas why I get an error? I wrote an *almost* identical app in VB (basic vs. c++) and it worked fine.

    My code (I know its not too pretty ):
    Code:
    /***********************************************************/
    /* bin2char-0.1.cpp - Binary to Character Converter v. 0.1 */
    /***********************************************************/
    #include <iostream>
    #include <cmath>
    #include <string>
    using namespace std;
    
    int main()
    { string bin_stream, char_stream;
      int ascii_num, char_start;
      int count = 0;
      char ch;
    
      cout << "Enter string to convert : ";
      cin >> bin_stream;
      if(bin_stream.length() % 8 != 0){
        cout << "Incorrect input string!!\n";
        return 0; }
      for(int i = bin_stream.length(); i > 0; i - 8){
        for(int j = 0; j <= 7; j++){
          char_start = count * j + 1;
          ch = bin_stream.at(char_start + j);
          if(ch == '1'){ ascii_num += (int)(pow((double)2,j)); }
        }
        count++;
        char_stream += (char)ascii_num;
      }
      cout << "Converted string:\n" << char_stream << endl;
      return 0;
    }
    Is it my code?

    Any help appreciated. Thanks.
    Last edited by dvldrmmr; 04-30-2004 at 12:16 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 11
    Last Post: 10-07-2008, 06:19 PM
  2. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  3. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  4. syntax error when defining vectors
    By starkhorn in forum C++ Programming
    Replies: 5
    Last Post: 09-22-2004, 12:46 PM
  5. UNICODE and GET_STATE
    By Registered in forum C++ Programming
    Replies: 1
    Last Post: 07-15-2002, 03:23 PM