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
Register
Register | 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
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old March 29th, 2005, 03:45 AM
Registered User
 
Join Date: Jan 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:
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

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

deleted
Reply With Quote
  #3 (permalink)  
Old March 29th, 2005, 05:09 AM
Authorized User
 
Join Date: Jul 2003
Location: , , .
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.
Reply With Quote
Reply


Thread Tools
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 07:33 AM
creating an array of size 2^16 bits scoobie C++ Programming 2 November 9th, 2005 07:59 PM
what data type in vb.net holds more thab 256 bits Hisham VB.NET 2002/2003 Basics 1 November 8th, 2004 04:35 AM
inverting bits sdilucca Visual C++ 0 July 2nd, 2004 02:14 PM



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


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