what is the output if the input is 10101001 101110 11011010 11001011 11001110 01010101 11011010 01100010 10110011 10001100?
And should I change program to Programme ?
#include
#include
#include
#include
#include
#include
#include
#include
int binaryToDecimal(const std::string& binary) {
int result = 0;
for (char c : binary) {
result = (result << 1) + (c - '0');
}
return result;
}
std::string binaryToHex(const std::string& binaryCode) {
std::bitset<8> bits(binaryToDecimal(binaryCode));
std::stringstream ss;
ss << std::hex << std::setw(2) << std::setfill('0') << static_cast
return ss.str();
}
std::string binaryToASCII(const std::string& binaryCode) {
std::string result;
for (size_t i = 0; i < binaryCode.length(); i += 8) {
std::bitset<8> bits(binaryCode.substr(i, 8));
char asciiChar = static_cast
result += asciiChar;
}
return result;
}
void decodeBinary(const std::string& binaryCode, std::string& originalInput, std::string& translation) {
std::cout << "May I present your 1s&0s Code: " << binaryCode << std::endl;
std::this_thread::sleep_for(std::chrono::seconds(2));
std::string asciiText = binaryToASCII(binaryCode);
std::cout << "Here's your Decoded ASCII: " << asciiText << std::endl;
originalInput = binaryCode;
translation = asciiText;
}
int main() {
std::string runProgram;
std::cout << "Wouldst thou like to runneth the program? (Yes/No): ";
std::cin >> runProgram;
if (runProgram == "Yes" || runProgram == "yes" || runProgram == "Y" || runProgram == "y") {
std::string binaryCode;
std::cout << "Giveth to me thine code of 1's and 0's: ";
std::cin.ignore();
std::getline(std::cin, binaryCode);
std::this_thread::sleep_for(std::chrono::seconds(2));
std::string hexCode = binaryToHex(binaryCode);
std::cout << "Ye ole Hex Code: 0x" << hexCode << std::endl;
std::this_thread::sleep_for(std::chrono::seconds(2));
std::string originalInput;
std::string translation;
decodeBinary(binaryCode, originalInput, translation);
std::cout << "Original Input: " << originalInput << std::endl;
std::cout << "Translation: " << translation << std::endl;
std::ofstream outputFile("what_you_had_said_was.txt");
if (outputFile.is_open()) {
outputFile << "1s&0s Code: " << binaryCode << std::endl;
outputFile << "Hex Code: 0x" << hexCode << std::endl;
outputFile << "Original Input: " << originalInput << std::endl;
outputFile << "Translation: " << translation << std::endl;
outputFile.close();
std::cout << "Translation saved to what_you_had_said_was.txt" << std::endl;
} else {
std::cout << "Apparently no one is home, I tried knockin'..." << std::endl;
}
std::string deleteEntry;
std::cout << "Wouldst thou like to delete the entry from the file? (Yes/No): ";
std::cin >> deleteEntry;
if (deleteEntry == "Yes" || deleteEntry == "yes" || deleteEntry == "Y" || deleteEntry == "y") {
if (std::remove("what_you_had_said_was.txt") == 0) {
std::cout << "Entry go poof." << std::endl;
} else {
std::cout << "For some reason unbeknownst to me, there has been an extreme malfunction. That file is still there." << std::endl;
}
}
} else {
std::cout << "Program terminated." << std::endl;
}
return 0;
}