How to remove leading zeros in decimal representation?

7 vues (au cours des 30 derniers jours)
Noor Fatima
Noor Fatima le 10 Août 2022
Commenté : Noor Fatima le 10 Août 2022
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?

Réponse acceptée

KSSV
KSSV le 10 Août 2022
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"

Plus de réponses (1)

Abderrahim. B
Abderrahim. B le 10 Août 2022
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

Catégories

En savoir plus sur Data Type Conversion dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by