Results 1 to 7 of 7
  1. #1
    salamjamal10 is offline Member
    Join Date
    Nov 2012
    Posts
    3
    Rep Power
    0

    Default 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?

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,014
    Rep Power
    20

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

    ** This space for rent **

  3. #3
    salamjamal10 is offline Member
    Join Date
    Nov 2012
    Posts
    3
    Rep Power
    0

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

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,014
    Rep Power
    20

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

    ** This space for rent **

  5. #5
    salamjamal10 is offline Member
    Join Date
    Nov 2012
    Posts
    3
    Rep Power
    0

    Default 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,

  6. #6
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default 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). --tolls
    Actually somebody helped me doing that part. So, I just need somebody to help me with the Java code itself. --salamjamal10
    Ah.... 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?".

    HELP: Java code to compress 0s using run-length compression technique-7102012232216iwsmt.jpeg

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,014
    Rep Power
    20

    Default Re: HELP: Java code to compress 0s using run-length compression technique

    Quote Originally Posted by salamjamal10 View Post
    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,
    Or, to put it another way, we are not a code factory.
    Please see my sig.

    You should be able to write the first steps I mentioned above, at the very least the user input.
    If you cannot then I suggest going back through your notes.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Replies: 1
    Last Post: 10-27-2012, 03:22 PM
  2. Replies: 7
    Last Post: 06-19-2012, 10:26 AM
  3. How to compress .dmp file using java
    By razzzmatazzz in forum New To Java
    Replies: 1
    Last Post: 02-25-2010, 10:34 AM
  4. Compress text in java
    By rakesh_n_mehta in forum Threads and Synchronization
    Replies: 2
    Last Post: 10-21-2009, 09:12 PM
  5. Data compression at 48 Mbyte/s in native Java
    By rlasse in forum Java Software
    Replies: 0
    Last Post: 03-17-2008, 02:33 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •