All SolutionsAll Solutions
⚙️
ABCD Message
Week 21, 2026
using std::map | Draw6 | C++ Solutions
#include "allheaders.hpp"
#include "main.hpp"
using namespace std;
//---------------------------------------------------------[VARIABLES]
vector<string>bcdStr;
string bcdString;
fstream infile;
string bcdToText(std::string bcdCode);
//-----------------------------------------------------[PROGRAM LOGIC]
int main()
{
infile.open("BCDdata.txt", ios::in | ios::out);
if(!infile.is_open())
{
cout << "An error has occured.\n";
}
while(getline(infile, bcdString))
{
bcdStr.push_back(bcdString);
}
int size = bcdStr.size();
for(int i = 0; i < size; i++)
{
string s = bcdToText(bcdStr[i]);
}
return 0;
}
//------------------------------------------------[FUNCTION DEFINITIONS]
string bcdToText(std::string bcdCode)
{
map<string, string> BCDMap
=
{
{"0000", "0"},
{"0001", "1"},
{"0010", "2"},
{"0011", "3"},
{"0100", "4"},
{"0101", "5"},
{"0110", "6"},
{"0111", "7"},
{"1000", "8"},
{"1001", "9"},
{"1010", "A"},
{"1011", "B"},
{"1100", "C"},
{"1101", "D"},
{"1110", "E"},
{"1111", "."}
};
size_t pos = 0;
while ((pos = bcdCode.find(' '))
!= std::string::npos)
{
std::string token = bcdCode.substr(0, pos);
if (BCDMap.find(token) != BCDMap.end())
{
std::cout << BCDMap[token];
}
else
{
std::cout << " ";
}
bcdCode.erase(0, pos + 1);
}
std::cout << BCDMap[bcdCode];// << std::endl;
return bcdCode;
}
break into nibbles, use std::map to decode | Draw6 | C++ Solutions
#include "allheaders.hpp"
#include "main.hpp"
using namespace std;
//----------------------[GLOBALS]
vector<string>wholeStr;
vector<string>bcdStr;
string bcdString, binString;
fstream infile, wholefile, temp;
void init_BCD_map(unordered_map<string, string> &BCDMap);
void bcdToText(string bcdCode);
void splitStr(const string& str);
// PROGRAM 52 - week 21 -------------------------------------[BEGIN LOGIC]------
int main()
{
try {
temp.open("tempfile", ios::in |ios::out | ios::trunc);//[split into nibbles]
wholefile.open("challenge21.bin", ios::in | ios::binary);//[challenge text]
while(getline(wholefile, binString))
{
wholeStr.push_back(binString);
}
int wholesize = wholeStr[0].length();
string getSplitStr = wholeStr[0];
splitStr(getSplitStr);
temp.close();
infile.open("tempfile", ios::in | ios::out);//[reopen nibbles file]
while(getline(infile, bcdString))
{
bcdStr.push_back(bcdString);
}
int size = bcdStr.size();
for(int i = 0; i < size; i++)
{
bcdToText(bcdStr[i]);
}
// PROGRAM 52 - week 21 ---------------------------------------[END LOGIC]------
}// end of try
catch (const runtime_error& exception)
{
cout << "Msg: " << exception.what() << "\n";
}
cout << "\n";
return 0;
}
//-------------------------------------------------------[FUNCTION DEFINITIONS]
void splitStr(const string& str)
{
for (size_t i = 0; i < str.length(); i += 4)
{
temp << str.substr(i, 4) << "\n";
}
}
//------------------------------------------------------------------------------
void bcdToText(string bcdCode)
{
map<string, string> BCDMap
=
{
{"0000", "0"},
{"0001", "1"},
{"0010", "2"},
{"0011", "3"},
{"0100", "4"},
{"0101", "5"},
{"0110", "6"},
{"0111", "7"},
{"1000", "8"},
{"1001", "9"},
{"1010", "A"},
{"1011", "B"},
{"1100", "C"},
{"1101", "D"},
{"1110", "E"},
{"1111", "."}
};
size_t pos = 0;
while ((pos = bcdCode.find(' '))
!= string::npos)
{
string token = bcdCode.substr(0, pos);
if (BCDMap.find(token) != BCDMap.end())
{
cout << BCDMap[token];
}
else
{
cout << " ";
}
bcdCode.erase(0, pos + 1);
}
cout << BCDMap[bcdCode];
return;
}
Python - Split, Convert and Print | BMC | Python Solutions
def msgToSetBits(msg: str, bitLen: int, rev: bool) -> list[str]:
solve = []
if rev: msg = msg[::-1]
for i in range(0, len(msg), bitLen):
solve.append(msg[i:i + bitLen])
return solve
def bitsToPackedBCD(msg: list[str]) -> str:
result = ""
for subBits in msg:
val = int(subBits, 2)
result += "." if val == 15 else str(val)
return result
# main
msg = "0011111100010100000101011001001001100101001101011000100101111001001100100011100001000110001001100100001100111000001100100111100101010000001010001000010000011001011100010110100100111001100100110111010100010000010110000010000010010111010010010100010001011001001000110000011110000001011001000000011000101000011000100000100010011001100001100010100000000011010010000010010100110100001000010001011100000110011110011000001000010100100000001000011001010001001100101000001000110000011001100100011100001001001110000100010001100000100101010101000001011000001000100011000101110010010100110101100101000000100000010010100001001000000100010001011101000101000000101000010000010000001001110000000110010011100001010010000100010000010101010101100101100100010001100010001010010100100010010101010010010011000000111000000110010110010001000010100010000001000010010111010101100110010110010011001101000100011000010010100001000111010101100100100000100011001101111000011001111000001100010110010100100111000100100000000110010000100100010100010101100100100001010110011010010010001101000110000000110100100001100001000001000101010000110010011001100100100000100001001100111001001101100000011100100110000000100100100100010100000100100111001101110010010001011000011100000000011001100000011000110001010101011000100000010111010010001000000101010010000010010010000010010110001010000010100100100101010000001001000101110001010100110110010000110110011110001001001001011001000000110110000000000001000100110011000001010011000001010100100010000010000001000110011001010010000100111000010000010100011010010101000110010100000101010001000101100000100101000011001100000101011100100111000000110110010101110101100101011001000110010101001100001001001000011000011000010001011100111000000110010011001001100001000101111001001100010000010100010001100001010100100000000111010001000110001000110111100110010110001001110100100101010110011100110101000110001000010101110101001001110010010010001001000100100010011110010011100000011000001100000001000110010100100100010010100110000011001101100111001100110110001001000100000001100101011001100100001100001000011000000010000100111001010010010100011000111001010100100010010001110011011100011001000001110000001000010111100110000110000010010100001101110000001001110111000001010011100100100001011100010111011000101001001100010111011001110101001000111000010001100111010010000001100001000110011101100110100101000000010100010011001000000000000001010110100000010010011100010100010100100110001101010110000010000010011101111000010101110111000100110100001001110101011101111000100101100000100100010111001101100011011100010111100001110010000101000110100001000100000010010000000100100010010010010101001101000011000000010100011001010100100101011000010100110111000100000101000001111001001000100111100101101000100100100101100010010010001101010100001000000001100110010101011000010001001000010010100100000010000110010110000010000110010000000011010001000001100000010101100110000001001101100010100101110111010001110111000100110000100110010110000001010001100001110000011100100001000100110100100110011001100110011001100000110111001010010111100000000100100110010101000100000101100101110011000101110011001010000001011000001001011000110001100001011001010100000010010001000101100101000101010100110100011010010000100000110000001001100100001001010010001000110000100000100101001100110100010001101000010100000011010100100110000110010011000100011000100000010111000100000001000000000000001100010011011110000011100001110101001010001000011001011000011101010011001100100000100000111000000101000010000001100001011100010111011101100110100100010100011100110000001101011001100000100101001101001001000001000010100001110101010101000110100001110011000100010101100101010110001010000110001110001000001000110101001101111000011101011001001101110101000110010101011101111000000110000101011101111000000001010011001000010111000100100010011010000000011001100001001100000000000110010010011110000111011001100001000100011001010110010000100100100001011001000010000000011001"
ans = bitsToPackedBCD(msgToSetBits(msg, 4, False))
print(ans)
Scan input for bcd, convert bcd to a char | greenya | Odin Solutions
package main
import "core:fmt"
import "core:strings"
// INPUT := #load("warehouse.txt", string)
INPUT := #load("input.txt", string)
BCD :: [dynamic; 4] byte
main :: proc () {
fmt.println("Input:", INPUT)
result := strings.builder_make()
defer strings.builder_destroy(&result)
bcd: BCD
for r in INPUT do if r=='0' || r=='1' {
append(&bcd, byte(r-'0'))
if len(bcd) == 4 {
char := bcd_to_char(bcd)
strings.write_byte(&result, char)
clear(&bcd)
}
}
fmt.println("Result:", strings.to_string(result))
}
bcd_to_char :: proc (b: BCD) -> byte {
n := b[0]*8 + b[1]*4 + b[2]*2 + b[3]
switch {
case n <= 9 : return '0' + n
case n == 15: return '.'
case : return '?'
}
}