01-28-2014 12:24 AM
Hi could you please let me know how can I convert Unsigned 16-bit integer ( series of 1 and 0s) to a 6 charachter string
for example 00000001 to "000001"
Thanks
01-28-2014 12:58 AM - edited 01-28-2014 01:05 AM
A 16 bit integer has 16 bits, so converting to 6 characters (0 or 1) seems impossible without losing information.
I don't understand the "(series of 1 and 0s)" expression. Are you talking about a U16 numeric?
In any case, this is probably just a simple formatting operation (try %06b). What have you tried?
01-28-2014 01:56 AM - edited 01-28-2014 01:59 AM
Altenbach -- I suspect that he is not intending the string to be binary representation. In decimal, a 16 bit integer has a maximum value of 65535, so six digits ought to be enough.
I am guessing that the first number is the actual bits, a binary number meant to be an example of the bits in the 16-bit integer, and the second is the digits of the output; not actually binary but the example has a digit which is one.
Tintin, did I get that right?
If that is true, than you probably want to get things like this:
0000 0000 0000 0010 should come out as "000002"
1000 0000 0000 0001 should come out as "032769"
Is that what you have in mind? My examples are in decimal; do you want decimal or hex? (I am guessing decimal; four digits would suffice for hex).
Batya
01-28-2014 02:03 AM - edited 01-28-2014 02:05 AM
If I got that right, so this would do:
01-28-2014 02:16 AM - edited 01-28-2014 02:21 AM
Well, we really need a better problem description.
If the input is a 16 character string of 0s and 1s (series of 1 and 0s), representing a U16 integer and we want a 6 character decimally formatted string, something as follows would do.
01-28-2014 02:32 AM - edited 01-28-2014 02:34 AM
Well, we really need a better problem description.
This is true. We're coming up with nice solutions to a few different problems, but do they have anything to do with what he wants to do?
Should we come up with a few more, or wait and see?