Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Java > Java and JDK > BOOK: Beginning Java 2
Password Reminder
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 29th, 2005, 04:45 AM
Registered User
Join Date: Feb 2005
Location: Welland, ontario, Canada.
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:

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.....



  #2 (permalink)  
Old March 29th, 2005, 05:34 AM
Authorized User
Join Date: Jul 2003
Location: , , .
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts

  #3 (permalink)  
Old March 29th, 2005, 06:09 AM
Authorized User
Join Date: Jul 2003
Location: , , .
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts

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.

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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

All times are GMT -4. The time now is 10:09 PM.

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