how to round the binary bit into 8 bit

조회 수: 7 (최근 30일)
ARJUN K P
ARJUN K P 2015년 9월 20일
댓글: zuyuan 2024년 9월 19일
for example:
4 = binary is 100 into 00000100
1=binary is 1 into 00000001 any matlab code...
result is 8 bit binary

답변 (2개)

James Tursa
James Tursa 2018년 7월 18일
편집: James Tursa 2018년 7월 18일
Not sure what the real question is, but dec2bin has an option for minimum number of digits. E.g.,
>> dec2bin(1,8)
ans =
00000001
>> dec2bin(4,8)
ans =
00000100
The result is of course char strings. If you want or need something else you will need to provide us with more details.
  댓글 수: 1
zuyuan
zuyuan 2024년 9월 19일
that's what I'm looking for, thanks!

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


Dimitris Kalogiros
Dimitris Kalogiros 2018년 7월 18일
Hi AR
The best you have to do is to use fi objects. I recommend to have a look on matlab help site on this topic.
By the way, I'm giving an example
x=4;
X=fi(x,0,8,0); % x:value, 0:signed or not, 8:bits, 0:fractional part
X.data
X.bin

카테고리

Help CenterFile Exchange에서 Numeric Types에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by