Path: news.mathworks.com!not-for-mail
From: "Bruno Luong" <b.luong@fogale.findmycountry>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Problem with very simple script
Date: Wed, 29 Oct 2008 17:22:01 +0000 (UTC)
Organization: FOGALE nanotech
Lines: 28
Message-ID: <gea63p$lqu$1@fred.mathworks.com>
References: <gea529$cgk$1@aioe.org>
Reply-To: "Bruno Luong" <b.luong@fogale.findmycountry>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1225300921 22366 172.30.248.35 (29 Oct 2008 17:22:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 29 Oct 2008 17:22:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 390839
Xref: news.mathworks.com comp.soft-sys.matlab:497849


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