Closed Thread
Results 1 to 2 of 2

Thread: A challenge for anyone who wants one : )

  1. #1
    digiology Guest

    A challenge for anyone who wants one : )

    Hi, I am trying to write a method that basically takes in a vector containing short objects which have variable legnth codes in them. I want to manipulate these shorts and create a new Vector of shorts that contain fixed length code versions of these;
    Right now you can think of the shorts as overlapping on its neighbour in the vector, some of the bits are spilling over into the next short.

    Heres an example to make it clearer
    every short should have two parts, a 3 bit 'id' that tells the algorithm how many bits folling these 3 bits are to be associated with the id. The id can be used to get this number of bits from an array:
    indexlengths[] = {7, 6, 8, 5, 4, 7, 9, 8}

    so, when the algorithm encounters id #2 (the in the 3 leftmost bits) it looks in this array in position 2 and then knows that following the id is 6 bits to be extracted. once this has been extracted a new short should created and, these 6 bits should be added but shifted over to the very right of the short(shifted 13-6 in this case) and this id should added but to the very leftmost 3 bits.
    so:


    010 1111110100000
    (id:2) (6 bits)

    should go to:

    010 0000000111111

    now this wouldn't be too much of a problem BUT the remaining bits that were discarded (in this case 0100000) must be kept and plugged to the next short in the vector

    so if the next short in the vector is
    1010000011111110

    it will have this remainder from the previous short plugged into the right of it
    010 0000101000001 and 'pushed' off is:1111110

    now this process must continue making sure that this remainder that was 'pushed' off in plugged in to the next short BUT FIRST the process that we started with must be applied, a new short is created(for which the resulting fixed legnth code will be stored in), the ID is extracted from the leftmost 3 bits (id: 0) of the current short and the number of bits to follow is found from the above array indexLengths[0] which is 7 bits. these 7 bits are shifted by (16-3)-7 = 6 positions to the right so they are stored in to the rightmost part of this new short and the id will stay at the leftmost 3 bits:
    010 0000000000101 'pushed off: 000001'

    so now we have both 1111110 and 000001 'pushed' off of the same short, as the length of bits of this remainder gets longer and reaches 16, a new short should be created and added to the result vector.

    One more example just to show it visually:

    this time the indexes after the 'id' part are all 6

    int[] indexLengths = {6, 6, 6, 6, 6, 6, 6, 6};

    a vector of 3 shorts:

    111 1000011111111, 011 0111111100000, 101 1000000000000,

    results in:

    111 0000000100001, 111 1111011 011111, 110 00001011000000, 000000


    looking at the first resulting short:

    (id) (6 bits that followed the index shifted to the right most 6 bits)
    111 0000000100001

    the remiander that had to be 'pushed off' is inserted in to the start of the next short and the process starts again.

    I know this is alot to ask, but any tips would be great, java isn't being any help when working with bits and shorts, for example when extracting the id (using a mask and then shifting to the right 13 places) I get negative numbers sometimes!
    Any suggestions on how to break this down into a managable problem to solve would be great too : )

    Thanks!

  2. CODECALL Circuit advertisement

     
  3. #2
    Void's Avatar
    Void is offline Programming Expert
    Join Date
    Jun 2006
    Posts
    410
    Rep Power
    23
    Wow, that is a long read. Sorry, don't think I can help you.
    Void

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Need Challenge and Ideas
    By ki4jgt in forum General Programming
    Replies: 4
    Last Post: 10-17-2010, 05:23 PM
  2. One challenge for the structure
    By DimaStudMaestro1 in forum C and C++
    Replies: 2
    Last Post: 03-08-2010, 06:20 PM
  3. VDU Challenge
    By adeel176 in forum Java Help
    Replies: 1
    Last Post: 01-25-2010, 05:19 PM
  4. challenge for someone
    By mandriva in forum MarketPlace
    Replies: 0
    Last Post: 11-14-2007, 03:07 AM

Tags for this Thread

Bookmarks

Posting Permissions

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