convert an array of 0s and 1s to binary & reverse
29 次查看(过去 30 天)
显示 更早的评论
hi Community,
I have an array of type double that contain only zeros and ones.
i want to convert it to binary value like below
[0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1] ----> [0 255]
and do the same thing in reverse
already tried de2bi()
but nothing !!!
2 个评论
Rik
2021-6-13
@Stephen, isn't that the normal encoding? 0-255 is a normal 8 bit range, right? Or am I confused?
采纳的回答
Walter Roberson
2021-6-14
编辑:Walter Roberson
2021-6-14
pad with 0 to a multiple of 8
2.^(7:-1:0) * reshape(padded, 8,[])
The result will be a vector of values 0 to 255
reverse:
bits = reshape(de2bi(bytes, 8),1,[])
and remember to remove the padding bits
0 个评论
更多回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Type Conversion 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!