-4

when I have binary code like '01010100011001010111001101110100", how can I convert this back to "test"?

Thanks.

  • 3
    What have you tried yourself? How did (or didn't) that work? Can you please show us your code (preferably in the form of a [Minimal, Complete, and Verifiable Example](http://stackoverflow.com/help/mcve)) and tell us what's wrong with it. And if you haven't done so yet, please [read about how to ask good questions](http://stackoverflow.com/help/how-to-ask). – Some programmer dude Jan 21 '16 at 18:55
  • 1
    You could write a program to do it, or maybe use pencil and paper and an ASCII table... Why not take your best guess and try something, then ask questions if you have any problems with it you can't solve? You may surprise yourself. – John Sensebe Jan 21 '16 at 18:59

2 Answers2

1

There is many ways to get this. It depends on the language. In general, you would break down the binary string in chunks of 8 bits (byte). Then you would calculate the decimal value of each byte. Link below goes over how to do that. Once you have the decimal value, you have each letter. From here, it depends on the language. In C you could make a char array of each and make a c-string.

http://www.wikihow.com/Convert-from-Binary-to-Decimal

You could also do a look up table.

user2899525
  • 105
  • 10
0
#include <iostream>
#include <string>
#include <climits>

int main( int, char ** )
{
   std::string str( "01010100011001010111001101110100" );

   std::string result;
   for( size_t i = 0; i < ( str.size() / CHAR_BIT ); ++i )
      result.push_back( static_cast< char >( stoi( str.substr( 8 * i, CHAR_BIT ), nullptr, 2 ) ) );

   std::cout << "result = " << result << std::endl;

   return 0;
}
George Houpis
  • 1,729
  • 1
  • 9
  • 5