필터 지우기
필터 지우기

Error in converting decimal to binary

조회 수: 2 (최근 30일)
Pat
Pat 2012년 12월 21일
a=[-5;5]
b=dec2bin(2^4+a);
b =
01011
10101
I get error for 5
b= dec2bin(mod(2^6+a,2^6))
I get
111011
000101
Why do I get values like this and where is the error made?
i have values like a=[-145 1 -2 10 199 51 -4]

답변 (1개)

Doug Hull
Doug Hull 2012년 12월 21일
>> a = [-5; 5];
middle = 2^4+a
dec2bin(middle)
middle =
11
21
ans =
01011
10101
I suspect that middle is not what you expected it to be.
  댓글 수: 3
Pat
Pat 2012년 12월 21일
how to convert a=[-145 1 -2 10 199 51 -4] to binary,
Walter Roberson
Walter Roberson 2012년 12월 21일
There are three distinct common ways to represent negative numbers in binary. You need to choose: separate sign; one's complement; two's complement.

댓글을 달려면 로그인하십시오.

카테고리

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