Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > BOOK: Beginning Java 2
|
BOOK: Beginning Java 2
This is the forum to discuss the Wrox book Beginning Java 2, SDK 1.4 Edition by Ivor Horton; ISBN: 9780764543654
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning Java 2 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 29th, 2005, 04:45 AM
Registered User
 
Join Date: Feb 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Turning strings into bits...help

Hi Everyone,

I am working on a Huffman coding application that reads the frequencies of all the bytes in the file, then builds a Huffman tree and creates codes for each byte value, depending on their frequency.
Now I have an array named codeTable[] containing 256 Strings for each 256 possible frequencies.

The codes in codeTable[] look like this:
00
01001
1001001

Now I need to output those codes to an BufferedStreamOuput. I need to find an efficient way to put those strings in the output file.
Each 1 and 0's should be 1 BIT long, therefore byte[] codeString = code.getBytes(); will not do the trick as it makes each 1 and 0 a byte long...thus making the output file bigger than the input(against the purpose of my application).

So what i need to figure out is a way to pack 1010101010 so i can write them out.

BufferedOuputStream as 2 write() methods, 1 that takes an int as parameter and the other takes a byte[] array.....

Help!!!

Pat

 
Old March 29th, 2005, 05:34 AM
Authorized User
 
Join Date: Jul 2003
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Default

deleted
 
Old March 29th, 2005, 06:09 AM
Authorized User
 
Join Date: Jul 2003
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It sounds like you need to convert Strings to integers. I think Integer.valueOf(String aString, int radix) might work for you.

edit: Never mind. Every int would be 4 bytes long.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Turning XML into HTML poole@daveandkate.fsnet.c XSLT 2 June 8th, 2006 05:20 PM
Turning Siblings into Children wolfie78uk XSLT 3 December 22nd, 2005 08:33 AM
creating an array of size 2^16 bits scoobie C++ Programming 2 November 9th, 2005 08:59 PM
what data type in vb.net holds more thab 256 bits Hisham VB.NET 2002/2003 Basics 1 November 8th, 2004 05:35 AM
inverting bits sdilucca Visual C++ 0 July 2nd, 2004 02:14 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.