Converting binary to Decimal

I need to write a program that converts a 4-Bit Binary number to a decimal and reverse. How can i write a function that converts 4-bit binary to decimal and decimal to binary? What way can i check that the input is actually binary?

回答 (2 件)

Walter Roberson
Walter Roberson 2011 年 4 月 13 日

0 投票

How exactly is the binary number represented?
Michael Finch
Michael Finch 2011 年 4 月 13 日

0 投票

Right now i have dialog box that ask the user for what conversion method they want. I need to set up a function that checks the number to make sure it is either 4-bit binary or a decimal. I have to verify the input as not exceeding four digits in case of change from binary to decimal, or exceeding two digits in the reverse operation. I have also to verify the input from the user if it is something other than B or D for the operation needed.

3 件のコメント

John D'Errico
John D'Errico 2011 年 4 月 13 日
So, you know what you need to do. It is time to start writing.
Michael Finch
Michael Finch 2011 年 4 月 13 日
I just don't seem to understand how to change the decimal to binary and binary to decimal. How can i check that the input was actually a 4-bit binary?
Walter Roberson
Walter Roberson 2011 年 4 月 14 日
You wrote, "[...] that checks the number [...]"
*What* number? How *exactly* is that number represented?

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

カテゴリ

質問済み:

2011 年 4 月 13 日

Community Treasure Hunt

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

Start Hunting!

Translated by