Results 1 to 7 of 7
- 11-14-2012, 05:23 PM #1
Member
- Join Date
- Nov 2012
- Posts
- 3
- Rep Power
- 0
HELP: Java code to compress 0s using run-length compression technique
Hello there, Can you help me guys to write a java program which inputs a string of 1s and 0s and compresses the 0s using the run-length compression technique
For example, the users enters this string:
000000000001000011000101
is replaced with just the number of 0s sequences without the number of 1s like this:
11 4 0 3 1
and then replace each decimal value of the above with a 4-bit binary value (nibble). Note: If you need to code a value larger than 15, you need to use two consecutive 4-bit nibbles.
for example for number 11 the binary value of it should be like this: 1011 0000
number 0 it will be like this: 0000 0000
for number 15 it will be like this: 1111 0000
Can someone help me with the Java codes?
- 11-14-2012, 05:35 PM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
Re: HELP: Java code to compress 0s using run-length compression technique
What have you done so far and where are you stuck?
Please ensure any code you post is in [code] tags [/code].
Also ensure you supply any compiler errors in full, highlighting the line they occur on.
If it runs then provide any exceptions that are thrown, including stack traces, also highlighting the line they are thrown from.
If it runs without exception, then you need to show what you rinput was and what result you saw and what result you expected to see.Please do not ask for code as refusal often offends.
- 11-14-2012, 05:54 PM #3
Member
- Join Date
- Nov 2012
- Posts
- 3
- Rep Power
- 0
Re: HELP: Java code to compress 0s using run-length compression technique
Honestly, I just have basic Java background. So I would appreciate helping me writing the code.
I have outlined what my code should look like in natural language and here is what I got.
To output the encoded sequence as decimals, I would say something like this:
(Iterate over) every character in the string. For each character do the following:
If it is a 0 we add 1 to the number of 0s currently read
If it is a 1, we:
append the number of currently read 0s to the output string
append 1 to the output string
set the number of currently read 0s to 0
If the current character is the last one, we append the number of 0s currently read, but only if we have read more than one 0
When we are done, we output the output-string
That was for the first part. I couldn't get the second part which is for replacing the decimal values to binary bits.
Please help me with codes if you can.
Thanks in advance ...
- 11-14-2012, 06:05 PM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
Re: HELP: Java code to compress 0s using run-length compression technique
So start from the beginning.
You need some code to prompt the user for a binary String (ie 0's and 1's).
Once you have that working then you need a loop over the String and start on your logic above.
You don't need anyone here to do that as you've already done the hard part of coming up with a plan.Please do not ask for code as refusal often offends.
- 11-14-2012, 06:24 PM #5
Member
- Join Date
- Nov 2012
- Posts
- 3
- Rep Power
- 0
Re: HELP: Java code to compress 0s using run-length compression technique
Actually somebody helped me doing that part. So, I just need somebody to help me with the Java code itself. Is there anybody that starts with me from scratch? I don't think it will be a long code.
I would appreciate that.
Thanks,
- 11-14-2012, 10:45 PM #6
Re: HELP: Java code to compress 0s using run-length compression technique
You need some code to prompt the user for a binary String (ie 0's and 1's). --tollsAh.... what part of user input isn't code? If you have done the user input portions already, go ahead and post them here and we can help you move forward (when you as a specific question of course). Your questions so far have been the rough equivalent of "How do I program games?".Actually somebody helped me doing that part. So, I just need somebody to help me with the Java code itself. --salamjamal10
- 11-15-2012, 09:39 AM #7
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
Re: HELP: Java code to compress 0s using run-length compression technique
Please do not ask for code as refusal often offends.
Similar Threads
-
Java gaming using OCR raster graphics, Java NEURAL NETWORK technique, please help me
By karthickjo in forum Java GamingReplies: 1Last Post: 10-27-2012, 03:22 PM -
Compress database using java coding?????..........
By Ranjiz in forum New To JavaReplies: 7Last Post: 06-19-2012, 10:26 AM -
How to compress .dmp file using java
By razzzmatazzz in forum New To JavaReplies: 1Last Post: 02-25-2010, 10:34 AM -
Compress text in java
By rakesh_n_mehta in forum Threads and SynchronizationReplies: 2Last Post: 10-21-2009, 09:12 PM -
Data compression at 48 Mbyte/s in native Java
By rlasse in forum Java SoftwareReplies: 0Last Post: 03-17-2008, 02:33 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks