Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Convert Binary String to an Integer array?.

30 views
Skip to first unread message

Sai

unread,
May 16, 2013, 7:20:09 AM5/16/13
to
Hi,
I doing a project where i need to mask ie is bitwise and of two hexadecimal numbers
eg: 401 and 402

I am kind of new to matlab and doing a very tedious way i am currently doing is:

A1 = 401; % int32, in the acutal part of my code, this A value will be int32
A2 = 402;

A1 = double(A1) % Coverting it to double
A2 = double(A2)

B1 = num2str(A1)
B2 = num2str(A2)

C1 = hex2num(B1)
C2 = hex2num(B1)

q = quantizer('double')

D1 = num2bin(q,C1) % Binary value
D2 = num2bin(q,C2) % Binary value

%E = bitand(401, 402) %% CANNOT DO BIT_WISE "AND" operation unless both input arguments are of same type ie...integer


all i want the ans to be is
1. I know that 401 is an hexadecimal number, how do i represent this 401 itself as in hexadecimal number?
- any help in this is greatly appreciated, cos most of my problem will be solved!!

or

2. convert the value of the D1 and D2 char string to a matrix like this
eg:
401 = '010000000001' as [0 1 0 0 0 0 0 0 0 0 0 1]
402 = '010000000001' as [0 1 0 0 0 0 0 0 0 0 1 0]
then in can carry on with the tedious process to continue with the bitwise and operation.

Any help is greatly appreciated or any suggestion also solves my problem, pls do so!

Sai

unread,
May 16, 2013, 7:21:09 AM5/16/13
to

Sai

unread,
May 16, 2013, 7:22:09 AM5/16/13
to

Matt Butts

unread,
May 16, 2013, 9:10:09 AM5/16/13
to
I am not sure if this completely answers your question, but I'll throw it out there:

>> str1 = dec2bin(base2dec('401',16))
str1 =
10000000001
>> str2 = dec2bin(base2dec('402',16))
str2 =
10000000010
>> bitand(str2num(str1(:))',str2num(str2(:))')
ans =
1 0 0 0 0 0 0 0 0 0 0

Sai

unread,
May 17, 2013, 1:50:09 AM5/17/13
to
"Matt Butts" wrote in message <kn2lrh$kb4$1...@newscl01ah.mathworks.com>...
Thanks a Lot Matt...It works like a charm :)
0 new messages