All SolutionsAll Solutions
🧑🚀
A Human Message
Week 4, 2026
bit shifting | Draw6 | C++ Solutions
//week4.cpp
//instructions: copy line long msg into a file named data.txt (single line, no spaces)
//compile with the following
//g++ -o week4 week4.cpp
//run atcommand line: week4 < data.txt > outfile.txt
#include <stdio.h>
int main(int argc, char * argv[])
{
unsigned char byte = 0;
int bits = 0;
for(;;)
{
char buffer[1024];
int len = fread(buffer, 1, sizeof(buffer), stdin);
// if there was a read error or EOF, stop
if (len <= 0)
break;
for(int i = 0; i < len; ++i)
{
switch(buffer[i])
{
// if a binary 1, turn on bit zero
case '1':
byte |= 1;
break;
// if a binary 0, do nothing
case '0':
break;
// if antyhing else, skip
default:
continue;
}
// incrment the counter, if we dont yet have 8 bits
// shift all the bits left by one
if (++bits < 8)
byte <<= 1;
else
{
// write out the complete byte
fwrite(&byte, 1, 1, stdout);
// reset for the next byte
bits = 0;
byte = 0;
}
}
}
// write out any remaining data if the input was not a multiple of 8 in length.
if (bits)
fwrite(&byte, 1, 1, stdout);
return 0;
}
Python - One loop | BMC | Python Solutions
binary = "00100010010010000110010101101100011011000110111100100000011001100111001001101111011011010010000001110100011010000110010100100000011000110110100001101001011011000110010001110010011001010110111000100000011011110110011000100000011100000110110001100001011011100110010101110100001000000100010101100001011100100111010001101000001011100010001000100000001011010010000001010110011011110111100101100001011001110110010101110010001000000011000100100000001001100010000000110010001011000010000000110001001110010011011100110111"
ans = ""
for i in range(0, len(binary), 8):
heheha = binary[i:i+8]
ans += chr(int(heheha, 2))
print(ans)
Python modular approach | rud | Python Solutions
def binary_to_text(binary: str) -> str:
input_bytes: list[str] = [binary[bit:bit + 8] for bit in range(0, len(binary), 8)]
char_values: list[str] = []
for byte in input_bytes:
char_values.append(chr(int(byte, 2)))
return "".join(char_values)
Rust minimal solution | [email protected] | Rust Solutions
fn main() {
const BITS: &str = "00100010010010000110010101101100011011000110111100100000011001100111001001101111011011010010000001110100011010000110010100100000011000110110100001101001011011000110010001110010011001010110111000100000011011110110011000100000011100000110110001100001011011100110010101110100001000000100010101100001011100100111010001101000001011100010001000100000001011010010000001010110011011110111100101100001011001110110010101110010001000000011000100100000001001100010000000110010001011000010000000110001001110010011011100110111";
let mut out = String::new();
for i in (0..BITS.len()).step_by(8) {
let byte = u8::from_str_radix(&BITS[i..i + 8], 2).unwrap();
out.push(byte as char);
}
println!("{}", out);
}
Pseudocode A Human Message | MarsKing | Pseudocode Solutions
FUNCTION BINARYTOTEXT(binary:STRING) RETURNS STRING
DECLARE Result:INTEGER
DECLARE ReturnString:STRING
ReturnString ← ""
FOR Count ← 1 TO LENGTH(binary) STEP 8
Result ← 0
FOR I ← 7 TO 0 STEP -1
IF MID(binary,(Count+7-I),1) = "1" THEN
Result ← Result + (2^I)
ENDIF
NEXT I
ReturnString ← ReturnString & CHR(Result)
NEXT Count
RETURN ReturnString
ENDFUNCTION
Python approach? | THOMAS L | Python Solutions
//Paste your solution here if you want to share it publicly
message = input()
n = len(message) // 8
for i in range(n):
a = message[i * 8 : (i + 1) * 8]
b = int(a, 2)
print(chr(b), end="")
Walking string and making runes | greenya | Odin Solutions
// https://program52.com/en/challenge/2026/5B7BB05B5
// - use "odin run ." to run the code
// - input1.txt and input2.txt should be nearby with the input data
package main
import "core:fmt"
import "core:strconv"
import "core:strings"
input1_bytes := #load("input1.txt")
input2_bytes := #load("input2.txt")
main :: proc () {
for bytes in ([2] [] byte { input1_bytes, input2_bytes }) {
text := strings.trim(string(bytes), "\n\r\t ")
for line in strings.split_lines(text) {
result := decode(line)
fmt.printfln("->|%s|\n<-|%s|", line, result)
}
}
}
decode :: proc (input: string, allocator := context.allocator) -> string {
assert(len(input)%8 == 0, "input length must be divisible by 8")
sb := strings.builder_make(allocator)
for i in 0..<len(input)/8 {
text := input[i*8:(i+1)*8]
number, ok := strconv.parse_int(text, base=2)
assert(ok)
strings.write_rune(&sb, rune(number))
}
return strings.to_string(sb)
}
python | Peiran D | Python Solutions
binary_string = "00100010010010000110010101101100011011000110111100100000011001100111001001101111011011010010000001110100011010000110010100100000011000110110100001101001011011000110010001110010011001010110111000100000011011110110011000100000011100000110110001100001011011100110010101110100001000000100010101100001011100100111010001101000001011100010001000100000001011010010000001010110011011110111100101100001011001110110010101110010001000000011000100100000001001100010000000110010001011000010000000110001001110010011011100110111"
# Split the binary string into 8-bit chunks
binary_chunks = [binary_string[i:i+8] for i in range(0, len(binary_string), 8)]
# Convert each binary chunk to its corresponding character
decoded_text = ''.join([chr(int(chunk, 2)) for chunk in binary_chunks])
print("Decoded text:")
print(decoded_text)
print("\n--- Alternative formatting ---")
# Let's also show the process step by step
print("\nCharacter-by-character breakdown:")
for i, chunk in enumerate(binary_chunks):
char = chr(int(chunk, 2))
print(repr(char))
this is ascii btw | AbsolutelyArsenal | C Solutions
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main() {
char inString[1024];
scanf("%s", inString);
int len = strlen(inString);
int numNibbles = len / 4;
// Arrays to store the intermediate steps
char hexStore[numNibbles + 1];
// 1 & 2: Process binary into Hex characters
for (int i = 0; i < numNibbles; i++) {
// Look at a 4-bit chunk
char chunk[5];
strncpy(chunk, &inString[i * 4], 4);
chunk[4] = '\0';
// Convert the 4-bit string to a hex char
if (strcmp(chunk, "0000") == 0) hexStore[i] = '0';
else if (strcmp(chunk, "0001") == 0) hexStore[i] = '1';
else if (strcmp(chunk, "0010") == 0) hexStore[i] = '2';
else if (strcmp(chunk, "0011") == 0) hexStore[i] = '3';
else if (strcmp(chunk, "0100") == 0) hexStore[i] = '4';
else if (strcmp(chunk, "0101") == 0) hexStore[i] = '5';
else if (strcmp(chunk, "0110") == 0) hexStore[i] = '6';
else if (strcmp(chunk, "0111") == 0) hexStore[i] = '7';
else if (strcmp(chunk, "1000") == 0) hexStore[i] = '8';
else if (strcmp(chunk, "1001") == 0) hexStore[i] = '9';
else if (strcmp(chunk, "1010") == 0) hexStore[i] = 'A';
else if (strcmp(chunk, "1011") == 0) hexStore[i] = 'B';
else if (strcmp(chunk, "1100") == 0) hexStore[i] = 'C';
else if (strcmp(chunk, "1101") == 0) hexStore[i] = 'D';
else if (strcmp(chunk, "1110") == 0) hexStore[i] = 'E';
else if (strcmp(chunk, "1111") == 0) hexStore[i] = 'F';
}
hexStore[numNibbles] = '\0';
// 3: Convert Hex pairs to ASCII characters
for (int i = 0; i < numNibbles; i += 2) {
// Take two hex digits (8 bits total) and convert to a byte
char hexPair[3] = { hexStore[i], hexStore[i+1], '\0' };
// strtol converts the string base-16 to a long integer
int asciiVal = (int)strtol(hexPair, NULL, 16);
printf("%c", (char)asciiVal);
}
printf("\n");
return 0;
}
Python | PaulZ | Python Solutions
Encoded = "00100010010010000110010101101100011011000110111100100000011001100111001001101111011011010010000001110100011010000110010100100000011000110110100001101001011011000110010001110010011001010110111000100000011011110110011000100000011100000110110001100001011011100110010101110100001000000100010101100001011100100111010001101000001011100010001000100000001011010010000001010110011011110111100101100001011001110110010101110010001000000011000100100000001001100010000000110010001011000010000000110001001110010011011100110111"
Decoded = int(Encoded, 2).to_bytes(len(Encoded) // 8, 'big').decode()
print(Decoded)
Pseudocode | program52 | Pseudocode Solutions
DECLARE binaryStr, message : STRING
DECLARE index : INTEGER
binaryStr ← "00100010010010000110010101101100011011000110111100100000011001100111001001101111011011010010000001110100011010000110010100100000011000110110100001101001011011000110010001110010011001010110111000100000011011110110011000100000011100000110110001100001011011100110010101110100001000000100010101100001011100100111010001101000001011100010001000100000001011010010000001010110011011110111100101100001011001110110010101110010001000000011000100100000001001100010000000110010001011000010000000110001001110010011011100110111"
FOR index ← 1 TO LENGTH(binaryStr) STEP 8
message ← message & byteToChar(MID(binaryStr, index, 8))
NEXT index
OUTPUT message
FUNCTION byteToChar(byte : STRING) RETURNS CHAR
DECLARE posVal, sum, stringIndex : INTEGER
posVal ← 128
sum ← 0
stringIndex ← 1
WHILE posVal >= 1 DO
IF MID(byte, stringIndex, 1) = "1" THEN
sum ← sum + posVal
ENDIF
posVal ← posVal DIV 2
stringIndex ← stringIndex + 1
ENDWHILE
RETURN CHR(sum)
ENDFUNCTION