How to convert a binary string to modulus values?

Let b = 111110000101101 be the binary string and it must be converted to decimal numbers in mod 18. The reverse program is also needed to covert the mod values back to the corresponding binary string.

Answers (2)

Use bin2dec and dec2bin

3 Comments

Sir I have to convert binary to modulus values and not to direct decimals..
What is the expected result for
b='111110000101101'
It must grouped such that the converted decimal numbers must contain only numbers ranging from 0 to 17 if mod 18 is needed. So here the grouping is 1111 10000 1011 01 and answer will be 15 16 11 1. so if I convert 15 16 11 1 back to binary it will be the original binary string 1111100000101101.

Sign in to comment.

Your scheme is ambiguous. If you want 1 to be represented by 01 then there is no obvious reason why it should know that you need to read past 11 (i.e., 3) to find 1111 (15).
Your scheme will need to read either 4 or 5 bits, not 2 or 4 or 5.
If you represent 16 as 10000 then you need to indicate how you will represent 8, which would normally be 1000 in binary. You cannot represent the 8 by adding an extra 0 to the end of it because that would get 10000 which you already said was 16. If you represent the 8 by adding an extra 1 to the end of it then you would get 10001 which you have implied would be 17. So you need to distinguish the 8 from 16 by prefixing the 1000 with a 0 to get 01000 . But if you do that then how are you going to represent 4, which would normally be 0100 ? Are you going to suffix it with a 1, getting 01001 ? Or are you going to use 01000 for 4 and use 01001 for 8?
Now you might claim that the 01 should be recognized as 1 because of the end-of-string being detected, but in that case why should 01 be generated on output for 1 at the end of string? Why not just 1 instead of 01?
When you generate 01 for the final 1, you lose the property that if you have another string of binary digits that represent a value, that you could just concatenate them on the end in order to get the first value followed by the second value, the way in decimal you can follow "42" by "7" to get 427. Unless you say that the two bits 01 always indicate that the result should be 1 base 18 and that you have some representation for values such as 0101 that would normally represent 5 and not 1 followed by 1.

Categories

Asked:

on 10 Jul 2015

Answered:

on 11 Jul 2015

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!