Skip to content

Instantly share code, notes, and snippets.

@rdp
Created April 14, 2023 04:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rdp/53f3b55bd67e0381590753c9a6b0b358 to your computer and use it in GitHub Desktop.
Save rdp/53f3b55bd67e0381590753c9a6b0b358 to your computer and use it in GitHub Desktop.
create EIA 608 byte pairs
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