LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how to convert Unsigned 16-bit integer to string

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

0 Kudos
Message 1 of 6
(6,047 Views)

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?

 

 

0 Kudos
Message 2 of 6
(6,040 Views)

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

0 Kudos
Message 3 of 6
(6,020 Views)

If I got that right, so this would do:

 

0 Kudos
Message 4 of 6
(6,011 Views)

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.

 

 

0 Kudos
Message 5 of 6
(6,000 Views)

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?  Smiley Happy

 

0 Kudos
Message 6 of 6
(5,989 Views)