How to convert an arbitrary rational to binary digits?
조회 수: 1 (최근 30일)
이전 댓글 표시
I have a number n1/n2, where n1 and n2 are integers. I would like to convert to base-2 and get the digits in order.
댓글 수: 0
답변 (3개)
Walter Roberson
2017년 10월 22일
bits = reshape((dec2bin(sscanf(num2hex(double(n1)/double(n2)),'%8x'),32) - '0').',1,[]);
... under at least one reasonable interpretation of what "bits" are appropriate.
For example, if n1 = 1 and n2 = 18446744073709551615 then one exact binary representation is an infinite repeating sequence of sixty-three 0's followed by a 1...
댓글 수: 0
Lai Yit Ming
2021년 10월 2일
Binary Converter Program - Write a program to accept a single binary number of up to 8 bits and display the equivalent in decimal. Using matlab
댓글 수: 1
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!