How NOT remove zeros from binary number?
7 次查看(过去 30 天)
显示 更早的评论
Hello,
i've a problem: when i have read binary data from device and when i have store this data in differents variables, MATLAB removed automaticly the first zero from every variable if this one starts with zero. If not starts with zero, all it's ok. I think that MATLAB made this for spare memory...
How could i made for matlab preserve this first zero of each variables?
For example:
Device gives me: 110101 and MATLAB stores 110101
but... if Device gives me: 010101 Matlab stores 10101
Remove the first zero.
Could you help me?
Thanks!
2 个评论
Image Analyst
2012-12-12
How are you capturing these numbers into MATLAB? What's the code? Are you capturing them as numbers? Can't you tell it to store the data into character strings?
采纳的回答
更多回答(2 个)
Walter Roberson
2012-12-12
How exactly is the data being received? You say it is binary. Does that mean that for the value 0, it is sending 8 bits (one character) all filled with 0 bits, and for the value 1, it is sending 8 bits with the last of them 1? Or does it mean that for the value 0, it is sending the character '0' (decimal value 48) and for the value 1, it is sending the character '1' (decimal value 49) ?
At some point you appear to be trying to store the number in decimal form. You probably shouldn't be doing that.
If the difficulty you are running into is that there are not enough digits when you display the number or send it somewhere else, and the number is in decimal form, then use
sprintf('%08d', TheNumber')
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!