Subexponential coding from c to matlab.

1 view (last 30 days)
Pooja
Pooja on 7 Aug 2013
I am having a C coding for the subexponential coding.Please tell me the matlab code written by me is correct and please suggest some ideas to implement the final step.
binary b= {k, if n<2^k
{floor(log2(n),if n>=2^k.
unary u= {0 if n<2^k
{b-k+1 if n>=2^k
Once these values are obtained, the code can be constructed by coding u in unary and continuing with the b LSB of n.
The matlab code written by me is as follows
function x=sec[n,k] %the value ok k is already estimated
if n<bitshift(2,k)
b=k;
u=0;
else
b=floor(log2(n));u=b-k+1;
x=[]%Once these values are obtained, the code can be constructed by coding u in unary and continuing with the b LSB of n.
I don't know to calculate x value in matlab.
The c code for calculating the code is given below
x =(((((1 < <( u )) -1) < < 1) < <( b )) | (n & ((1 < <( b )) -1)));
we build the unary code of u, which can be obtained by shifting a 1 bit u positions to the left and subtracting 1 to the result. A zero stop-bit can be added by shifting another position to the left the resulting value. The next operation is to append to this value the b LSB of n expressed in plain binary code. In order to do this the non-signicant bits of n must be discarded that is, theall-zero Most Signicant Bits (MSB) | by applying a mask that keeps the b LSB. A bit-wise OR operation with the truncated value of n will produce the required output.Once b and u are available, the subexponential code can be actually computed.
Please help me. Thankyou..
  4 Comments
dpb
dpb on 8 Aug 2013
Not to mention you then came after me..._not_ how to make friends and win help... :(
Jan
Jan on 8 Aug 2013
Edited: Jan on 8 Aug 2013
@Pooja: Contributors, who do not like to be pushed, might tend to ignore your question as a reaction. Pushing causes the impression, that somebody thinks, that his time is more important than the time of others. But it is not surprising, that the others have a different opinion.

Sign in to comment.

Answers (0)

Categories

Find more on Resizing and Reshaping Matrices in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!