How to convert the digits of a number in a higher number base to an array

3 ビュー (過去 30 日間)
Ernest Adamtey
Ernest Adamtey 2021 年 8 月 2 日
編集済み: dpb 2021 年 8 月 2 日
I converted 32 to base 18 using the code
A=dec2base(32,18)
and the output was
'1B'
I want to convert the digits of 1B to an array [1 B]. so i used the code
num2str(A)-'0'
Which gave me an output
ans =
1 21
Instead of ans= 1 B. Please help.
  8 件のコメント
Ernest Adamtey
Ernest Adamtey 2021 年 8 月 2 日
thank you very much. It worked
dpb
dpb 2021 年 8 月 2 日
編集済み: dpb 2021 年 8 月 2 日
Newer releases of Matlab do support hexadecimal notation, but otherwise, only base 10 numbers are allowed outside of text datatypes." @Rik
While not really pertinent to the discussion, Forth has the system constant BASE that lets one define the base dynamically...
BINARY
...everything here in base 2
DECIMAL
...now we're back in base 10
that is extremely handy and that I miss.
: DECIMAL 10 BASE ! ;
: HEX 16 BASE ! ;
: OCTAL 8 BASE ! ;
: BINARY 2 BASE ! ;
are the common defining words. Of course, one needs be certain DECIMAL is in effect when defining the above!!! :)
Just a sidebar into days of yore..."we now return you to your regular programming".

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by