필터 지우기
필터 지우기

How to remove leading zeros in decimal representation?

조회 수: 6 (최근 30일)
Noor Fatima
Noor Fatima 2022년 8월 10일
댓글: Noor Fatima 2022년 8월 10일
A = [23, 15, 256, 75];
B= dec2bin(A)
B =
4×9 char array
'000010111'
'000001111'
'100000000'
'001001011'
But I'm interested in output B as;
10111
1111
100000000
1001011
I want to remove leading zeros?

채택된 답변

KSSV
KSSV 2022년 8월 10일
A = [23, 15, 256, 75];
B= dec2bin(A)
B = 4×9 char array
'000010111' '000001111' '100000000' '001001011'
strip(string(B),'left','0')
ans = 4×1 string array
"10111" "1111" "100000000" "1001011"

추가 답변 (1개)

Abderrahim. B
Abderrahim. B 2022년 8월 10일
Hi!
Use str2num.
A = [23, 15, 256, 75];
B= dec2bin(A)
B = 4×9 char array
'000010111' '000001111' '100000000' '001001011'
B = str2num(B)
ans = 4×1
10111 1111 100000000 1001011
Hope this helps

카테고리

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