netbeans - Read/Write bits for Huffman coding in java -


i have huffman coding project in first step obtain code of each character depends on huffman tree.i obtain code of each character example : = 01 , b= 101 , c = 111.these codes string , want save them in file .cmp extension in binary example have text such : abc , encoding is:01101111 how can write them file binary value in file .cmp extension , after read them , decode them?

hopefully know bytes , integers consist of bits, need build little queue of bits single integer containing bits , integer tracks number of bits in first integer, accumulating bits using shift , or operators. once have accumulated byte, write out , shift out of queue. e.g. put n bits in buf |= val << bits; bits += n;, , pull bits out if have enough: while (bits >= 8) { write_out(buf & 0xff); buf >>= 8; bits -= 8;. make sure integer large enough handle largest value of n have. i.e., buf needs able hold maxn+7 bits, since while loop never leave more 7 bits in buffer.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -