필터 지우기
필터 지우기

How to apply dec2bin to char array?

조회 수: 5 (최근 30일)
Ammy
Ammy 2022년 3월 11일
편집: Stephen23 2022년 3월 12일
I have a data as char
a ='1234567';
dec2bin(a) gives
6×6 char array
'110001'
'110010'
'110011'
'110100'
'110101'
'110110'
but I want the result like dec2bin(123456)= '11110001001000000'
How to apply dec2bin to a char value to get a sinle out put ?
  댓글 수: 1
Stephen23
Stephen23 2022년 3월 11일
a ='1234567';
b = dec2bin(str2double(a))
b = '100101101011010000111'

댓글을 달려면 로그인하십시오.

채택된 답변

Stephen23
Stephen23 2022년 3월 12일
편집: Stephen23 2022년 3월 12일
"there is a problem with more digits in a like a='12362534624362643243256346523462'..."
The DOUBLE numeric class can only store 15 or so decimal digits or precision, it cannot store that entire number that you have shown without some loss of information. So converting to a scalar numeric using STR2NUM, STR2DOUBLE, SSCANF, or something similar simply will not work if you want all of the information. You will have to find an alternative approach, for example download BASE2BASE:
and use it like this:
a = '12362534624362643243256346523462';
b = base2base(a,10,2)
b = '10011100000010011000000011110110100110100000111111110111001000110111011110100110000110110011011101000110'

추가 답변 (1개)

KSSV
KSSV 2022년 3월 11일
a ='1234567';
dec2bin(str2num(a))
ans = '100101101011010000111'
  댓글 수: 1
Ammy
Ammy 2022년 3월 12일
@KSSV Thank you, but there is a problem with more digits in a
like
a='12362534624362643243256346523462'
str2num(a)= 1.2363e+31
and then not giving the right output in binary form

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by