Filter löschen
Filter löschen

Charecter to binary form

1 Ansicht (letzte 30 Tage)
Vishnu M S
Vishnu M S am 30 Jan. 2013
I have a character A. I converted this into a binary form(say B). I need to perform some operations using B. While doing this I need to check whether the element B(1)=1 or 0.
For doing so, I write
if B(1)==1
But it doesn't work. It works when I written like this-
if B(1)=='1'
What is the reason? Please tell me...
  2 Kommentare
Jurgen
Jurgen am 30 Jan. 2013
Apparently B is still a character array. Would help if you said how you converted it. Type whos B to see the type.
Jan
Jan am 30 Jan. 2013
I do not understand, what the "binary form" of a character is. Please post the corresponding Matlab code to clear the details.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Oleg Komarov
Oleg Komarov am 30 Jan. 2013
You are comparing the char '1' with the numeric 1.
>> double('1')
ans =
49
as in the ASCII table.
You have to rescale '1' to 1:
'1'-'0' == 1
and in your case
B(1)-'0' == 1

Weitere Antworten (0)

Kategorien

Mehr zu Data Type Conversion finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by