How NOT remove zeros from binary number?
7 views (last 30 days)
Show older comments
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 Comments
Image Analyst
on 12 Dec 2012
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?
Accepted Answer
Walter Roberson
on 12 Dec 2012
valorsTramaBin_15 = dec2bin(valorsTrama(15,:), 8); %force 8 bits output
More Answers (2)
Arthur
on 12 Dec 2012
Hi!
Try convert the data to a string array before you store in a variable
0 Comments
Walter Roberson
on 12 Dec 2012
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 Comments
See Also
Categories
Find more on Variables in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!