Jump to content

Bitwise IO: Difference between revisions

Line 1,455:
ASCII 7-bit character string compression and decompression, to demonstrate bit twiddling. Implemented as generic IO, so that file handles are usable with the same functions.
<lang Julia>
 
function compress7(inio, outio)
nextwritebyte = read(inio, UInt8) & 0x7f
Line 1,498 ⟶ 1,497:
outs = IOBuffer()
newouts = IOBuffer()
 
compress7(ins, outs)
seek(outs,0)
expand7(outs, newouts)
 
println("Initial string of length $(length(str)): ", String(ins.data))
println("Compressed to length $(length(outs.data)): ", outs.data)
println("Decompressed string: ", String(newouts.data))
</lang>
{{data}}<pre>
<pre>
Initial string of length 88: These bit oriented I/O functions can be used to implement compressors and decompressors.
Compressed to length 77: UInt8[0x54, 0x74, 0x79, 0x5e, 0x06, 0x89, 0xd3, 0x74, 0xd0, 0x5b, 0x9e, 0x2e, 0xbb, 0xe9, 0x65, 0x32, 0x28, 0xf9, 0x7a, 0x82, 0xcc, 0x75, 0xf7, 0x98, 0x9e, 0x7e, 0xbb, 0xe7, 0xa0, 0x71, 0xd8, 0x0d, 0x12, 0x97, 0x41, 0xf5, 0x79, 0x99, 0x0c, 0xa2, 0xbf, 0x41, 0xe9, 0x36, 0x9c, 0x5d, 0x6e, 0x97, 0xdd, 0x74, 0xd0, 0xf8, 0xdd, 0x86, 0xcb, 0xcb, 0xf3, 0xf9, 0x5b, 0x3e, 0x07, 0x85, 0xdd, 0x64, 0x10, 0xb9, 0x3c, 0x7e, 0xb7, 0xe1, 0xf2, 0xf2, 0x7c, 0xfe, 0x96, 0xcf, 0x5d]
Decompressed string: These bit oriented I/O functions can be used to implement compressors and decompressors.</pre>
</pre>
 
=={{header|Kotlin}}==
4,108

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.