Thread Subject: Problem with very simple script

Subject: Problem with very simple script

From: Clemens

Date: 29 Oct, 2008 17:04:09

Message: 1 of 5

Hi

I have a very simple problem. I have a 32-bit integer value and
I wanna store each byte of this word in one chunk of 8-bits. So my idea
was using a bitmask that extracts me each byte and then I wanna use
bitsra to rightshift the extract byte to the LSB and use then another
bitand to extract the final byte value. However, in the code fragement
below I get the error message that bitsra cant be used on values from
type 'double'. Anyone an idea how I could get around this problem?

LSB = 255;
mask = 255;
value = 3545883001; %D359E179

chunk(1) = bitand(value,mask);

for i=2:4
   mask = bitshift(mask,8);
   chunk(i) = bitand(bitsra(bitand(value,mask),(i-1)*8),LSB);
end

Many thanks,
Clemens!

Subject: Problem with very simple script

From: Bruno Luong

Date: 29 Oct, 2008 17:22:01

Message: 2 of 5

Clemens <Clemi@hotmail.com> wrote in message <gea529$cgk$1@aioe.org>...
> Hi
>
> I have a very simple problem. I have a 32-bit integer value and
> I wanna store each byte of this word in one chunk of 8-bits. So my idea
> was using a bitmask that extracts me each byte and then I wanna use
> bitsra to rightshift the extract byte to the LSB and use then another
> bitand to extract the final byte value. However, in the code fragement
> below I get the error message that bitsra cant be used on values from
> type 'double'. Anyone an idea how I could get around this problem?
>
> LSB = 255;
> mask = 255;
> value = 3545883001; %D359E179
>
> chunk(1) = bitand(value,mask);
>
> for i=2:4
> mask = bitshift(mask,8);
> chunk(i) = bitand(bitsra(bitand(value,mask),(i-1)*8),LSB);
> end
>
> Many thanks,
> Clemens!

Please take a look at function TYPECAST

Bruno

Subject: Problem with very simple script

From: Clemens

Date: 29 Oct, 2008 17:59:44

Message: 3 of 5

Bruno Luong wrote:
> Clemens <Clemi@hotmail.com> wrote in message <gea529$cgk$1@aioe.org>...
>> Hi
>>
>> I have a very simple problem. I have a 32-bit integer value and
>> I wanna store each byte of this word in one chunk of 8-bits. So my idea
>> was using a bitmask that extracts me each byte and then I wanna use
>> bitsra to rightshift the extract byte to the LSB and use then another
>> bitand to extract the final byte value. However, in the code fragement
>> below I get the error message that bitsra cant be used on values from
>> type 'double'. Anyone an idea how I could get around this problem?
>>
>> LSB = 255;
>> mask = 255;
>> value = 3545883001; %D359E179
>>
>> chunk(1) = bitand(value,mask);
>>
>> for i=2:4
>> mask = bitshift(mask,8);
>> chunk(i) = bitand(bitsra(bitand(value,mask),(i-1)*8),LSB);
>> end
>>
>> Many thanks,
>> Clemens!
>
> Please take a look at function TYPECAST

I will, but I just see that bitsra is not supported by matlab 2006a. Is
there another way I can shift the values 6 bits to the RIGHT?

Many thanks,
Clemens

Subject: Problem with very simple script

From: Bruno Luong

Date: 29 Oct, 2008 18:09:01

Message: 4 of 5

Clemens <Clemi@hotmail.com> wrote in message <gea8ag$p8r$1@aioe.org>...
. Is
> there another way I can shift the values 6 bits to the RIGHT?
>

floor(r/2^6)?

Bruno

Subject: Problem with very simple script

From: Walter Roberson

Date: 29 Oct, 2008 19:05:20

Message: 5 of 5

Clemens wrote:
> I just see that bitsra is not supported by matlab 2006a. Is
> there another way I can shift the values 6 bits to the RIGHT?

I don't see any bitsra in R2007a.

To shift bit values to the right, use bitshift with a negative shift.

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Contact us at files@mathworks.com