# Numeric to binary?

Hi,
If I use this code to convert a text string into binary:

``textfield2.text = Bin(ASC(textfield1.text))``

Could someone please advise me how I do the same BUT for a numeric string?
Is it simply:

``textfield2.text = Bin(Val(textfield1.text))``

I cannot test as I am on my iPad.

Thanks.

1. ASC only converts the FIRST character (see http://documentation.xojo.com/index.php/Asc) not the entire string. to convert the entire string you need a loop that does each character in it

2. “numeric string” ? a string that holds numbers ? an example of what you mean would be good

Norman - regarding point 1 - yes, I already use a loop

Regarding point 2:
For example - if I enter the text “1” - I get the result: 00110001, but how do I get the binary value for the numeric value 1?

Thanks.

ah … as you wrote bin(val(field))
since what you want is the binary representation of the NUMERIC value 1 not the string that contains the character “1”

??
So does that mean that this would be correct:

``textfield2.text = Bin(Val(textfield1.text))``

[quote=132579:@Richard Summers]So does that mean that this would be correct:

textfield2.text = Bin(Val(textfield1.text))[/quote]
I believe you’d have to convert that to a string value if you’re placing it back in a text field, so:

``textfield2.text = str(Bin(Val(textfield1.text)))``

Thanks Don

[quote=132585:@Don Lyttle]I believe you’d have to convert that to a string value if you’re placing it back in a text field, so:

``textfield2.text = str(Bin(Val(textfield1.text)))``

No. Bin returns a string. No additional conversion is necessary.

So this is correct?

``textfield2.text = Bin(Val(textfield1.text))``

Yes. That is correct.

Thanks everyone