What would the code look like to convert a positive decimal (base 10 integer) to its binary form (base 2)?
Mostra commenti meno recenti
I am tasked with developing a code that will convert a integer to binary form and display the result. I cannot get my code to work. What would the code look like to perform such an action?
Risposte (3)
Birdman
il 17 Gen 2018
You need to use dec2base command. To convert 23 decimal number to its base 2 representation, type
dec2base(23,2)
>> dec2bin(123)
ans = 1111011
If you want DIY code, then you will need mod and a loop.
Walter Roberson
il 17 Gen 2018
Examine:
TheInt = 1736;
bitget(uint32(TheInt), 32:-1:1)
Discard leading 0 values if you want.
Categorie
Scopri di più su Data Type Conversion in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!