Dcimal to binary conversion of float numbers and vice-versa

조회 수: 11 (최근 30일)
Pranoy
Pranoy 2012년 1월 29일
we are using this code to convert float values to binary...
B=-1.92
b=dec2bin(typecast(single(B),'uint32'),32)
but how do i convert it back to decimal...???

답변 (1개)

Walter Roberson
Walter Roberson 2012년 1월 29일
B = double( typecast(uint32(bin2dec(b)),'single') );
  댓글 수: 2
Pranoy
Pranoy 2012년 1월 30일
thnks for replyin....
but i get an error..
"Error using ==> bin2dec at 54
Binary string may consist only of characters 0 and 1"..
wt to do??
Walter Roberson
Walter Roberson 2012년 1월 30일
Your output stored in "b" is output from dec2bin(), which will always be characters 0 and 1. Those characters are then sent to bin2dec, where they *will* be characters 0 and 1.
The code is correct for what the functionality you asked, to convert the dec2bin output back. If you are getting the error you quote, then that is not what you are trying to do.

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

카테고리

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