decimal to binary conversion without using dec2bin or de2bi

조회 수: 4 (최근 30일)
Harish Maradana
Harish Maradana 2014년 12월 11일
답변: osman 2014년 12월 11일
decimal to binary conversion without using dec2bin or de2bi

답변 (2개)

Geoff Hayes
Geoff Hayes 2014년 12월 11일
Harish - one (not so efficient) way is to check each bit in the unsigned integer. If it is a one, then write a one to your string, else write a zero. Use class to determine the data type (uint8, uint16, etc.) and the number of bits to loop over. Use bitshift on your mask (which starts at one) to shift the one bit in the mask to the left at each iteration of your loop, and use bitand on your integer and mask to see if the bit in question is a one or not.

osman
osman 2014년 12월 11일
q = quantizer('fixed', 'Ceiling', 'Saturate', [5 4]) num2bin(q,yourvariable); in above example num2bin convert your variable in a fixed point manner. total of five bits but last four bit is in fractional part.

카테고리

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