Created
April 14, 2023 04:57
-
-
Save rdp/53f3b55bd67e0381590753c9a6b0b358 to your computer and use it in GitHub Desktop.
create EIA 608 byte pairs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
to_encode = "abcdABCD" | |
outy = Array(UInt8).new | |
to_encode.each_char{|c| | |
if c.in_set?("A-Z") | |
outy << 0x41_u8 + (c - 'A') # https://en.wikipedia.org/wiki/EIA-608#Characters | |
elsif c.in_set?("a-z") | |
outy << 0x61_u8 + (c - 'a') | |
else | |
raise "don't translate more chars yet" | |
end | |
} | |
# add parity bit | |
outy.map!{|c| | |
parity = true; | |
(0..7).each{|bit_count| | |
if c.bit(bit_count) == 1 | |
parity = !parity | |
end | |
} | |
if parity | |
c = c | 0b10000000; # add parity bit | |
end | |
c | |
} | |
outy.each{|c| puts "%08b" % c } | |
File.open(ARGV[0], "w") { |f| | |
outy.each{|c| # punt! | |
f.write_byte c | |
} | |
} | |
puts "wrote to #{ARGV[0]}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment