Lost Password?


Go Back   CodeCall Programming Forum > Software Development > General Programming

General Programming Non language specific, Assembly, Linux/Unix, Mac and anything not covered in other topics. Talk about Programming Theory here.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-27-2007, 10:22 PM
digiology digiology is offline
Newbie
 
Join Date: Feb 2007
Posts: 1
Rep Power: 0
digiology is on a distinguished road
Default 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!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 03-03-2007, 04:14 PM
Void's Avatar   
Void Void is offline
Programming Expert
 
Join Date: Jun 2006
Posts: 411
Rep Power: 11
Void is on a distinguished road
Default

Wow, that is a long read. Sorry, don't think I can help you.
__________________
Void
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT -5. The time now is 01:33 PM.

Contest Stats

WingedPanther ........ 2753.6
Xav ........ 2704
Brandon W ........ 1702.32
John ........ 1207.73
marwex89 ........ 1175.24
morefood2001 ........ 966.05
dcs ........ 655.75
Steve.L ........ 475.59
orjan ........ 418.58
Aereshaa ........ 383.54

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 98%

Ads