tags:

views:

63

answers:

1

Hi,

This is a follow up question from a previous SO question. Now I have a bit which I have spread it into 8 bits. I have use Amro's solution to spread the bit to 8 bits. Now I want an inverse way to convert the 8bits back to the single bit.

I have only managed to implement the inverse using for loop which take alot of time in the application.

Is there a faster way of doing it?

+2  A: 

Since you are using the solution I suggested last time, lets say you have a matrix N-by-8 of these 'bits' where each row represent one 8-bit binary number. To convert to decimal in a vectorized way, its as simple as:

» M = randi([0 1], [5 8])      %# 5 random 8-bit numbers
M =
     1     0     1     0     1     0     1     1
     0     1     1     0     1     1     1     0
     1     1     0     1     1     0     1     1
     1     0     0     0     0     1     1     0
     1     0     0     1     0     1     1     0
» d = bin2dec( num2str(M) )
d =
   171
   110
   219
   134
   150

An alternative solution:

d = sum( bsxfun(@times, M, power(2,7:-1:0)), 2)
Amro
The bit is no longer decimal, it is just 0 or 1, it is really just bit. Meaning the 8 bits is just representing is it a 0 or 1. So my inverse lookup table only have 2 entries.
HH
well If i'm getting this right, you just look at the rightmost column since the others will be all zeros, ie `d = M(:,8)`. Is that what you meant?
Amro
Well, no. I'm doing CDMA Spreading for example, 01101100 is a spread code and it represent bit 0 and the complement of the spread code 10010011 represent bit 1. So now I have a M x 8 matrix, the whole matrix just comprise the spread code and its complement. Now I just want to despread it by turning the 8 bits back into the bit it represent. Sorry for the confusion.
HH
ok, then cant you differentiate between the two codes simply by looking at any one column (since the codes are complement to each other)?
Amro
Oh. Ok, I get your idea. Thanks!!!
HH

related questions