Decimal to binary, bit reversal of binary and binary to decimal
조회 수: 9 (최근 30일)
이전 댓글 표시
Hi,
I would like to get the feedback on the following code. I am getting the incorrect number when I convert the binary numbers back to decimal at the end.
First of all, I have converted 1 through 1024 decimal numbers to binary and stored that to b. After that I performed the bit reversal using the fliplr command. I am getting the correct information until this point. But, when I tried to convert those bit reversed numbers to Decimal, I am not getting the correct numbers back . Any feedback on this? Help is much appreciated.
Code:
clear all
d = (1:1024)';
b = de2bi(d,'left-msb');
X = fliplr(b);
Y= bi2de(X, 'left-msb')
댓글 수: 1
Guillaume
2019년 7월 3일
편집: Guillaume
2019년 7월 3일
I don't have the relevant toolbox to test, but it seems to me the above could be simplified to:
d = (1:1024)';
b = de2bi(d, 'left-msb');
Y = bi2de(b, 'right-msb');
Now, with your statement "I am not getting the correct numbers back". Are you not getting a sequence starting with:
1024
512
1536
256
1280
768
1792
If that's what you're getting, then it is correct (and it's your expectations that are wrong).
답변 (2개)
Basil C.
2019년 7월 3일
I suppose the error has to do with the command 'fliplr'
Could you rather try the function 'flipud'
X = flipud(b);
댓글 수: 0
Abhishek Kumar
2019년 7월 3일
편집: Abhishek Kumar
2019년 7월 3일
Hi Riddhi
What is the output you are getting and what is the output that you think you should get?
I tried running the same program, I was getting the right output.
X stores the flipped bits, so when you convert it to decimal, you get the output of the flipped bits.
If you want the order in reversed fashion, try flipud.
for more info try : >>help flipud
Below, is my code's output.
>> d
d =
1
2
3
4
5
6
7
8
9
10
>> b
b =
0 0 0 1
0 0 1 0
0 0 1 1
0 1 0 0
0 1 0 1
0 1 1 0
0 1 1 1
1 0 0 0
1 0 0 1
1 0 1 0
>> X
X =
1 0 0 0
0 1 0 0
1 1 0 0
0 0 1 0
1 0 1 0
0 1 1 0
1 1 1 0
0 0 0 1
1 0 0 1
0 1 0 1
>> Y
Y =
8
4
12
2
10
6
14
1
9
5
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 PHY Components에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!