Boolean to Text
Reply | Flag | Categorize
AriMB 06 Feb 2013 17:29
AriMB

Included page "member:arimb" does not exist (create it now)


Guest

Wikidot community,
I have an idea to make a program that takes a string of 1's and 0's in sets of five and translates them into letters so that A is 11111, B is 11110, C is 11101, D is 11100, all the way to Z. Then output this string of letters as a string. Please paste the text as a reply.

Goodluck!

Attachment:

Anonymous 06 Feb 2013 18:53
Anonymous

Included page "member:anonymous" does not exist (create it now)


Guest

Sooo…
Reverse binary?

Attachment:

AnonymousBoba Foxx 06 Feb 2013 18:57
Anonymous

Included page "member:anonymous" does not exist (create it now)

Boba Foxx
Guest

If it is inverted binary, then this should do it:

:Delvar B
:Input "String?",str1
:if 5≠length(str1
:stop
For(Z,1,5
:B+1(sub(str1,Z,1)=2^(Z-1
end

should work :)

Attachment:

AnonymousBoba Foxx 06 Feb 2013 19:56
Anonymous

Included page "member:anonymous" does not exist (create it now)

Boba Foxx
Guest

Correction:

:Delvar B
:Input "String?",str1
:if 5≠length(str1
:stop
:For(Z,1,5
:B+1(sub(str1,6-Z,1)=2^(Z-1
:end
Ans→X    //not sure if needed, replace the x's on the following lines with Ans if it's not
:If X<5 or X=31
:Stop
:Sub("ABCDEFGHIJKLMNOPQRSTUVWXYZ",X,1

Attachment:

Anonymous 06 Feb 2013 20:17
Anonymous

Included page "member:anonymous" does not exist (create it now)


Guest

could you please explain what this does? Because I do not think we are thinking of the same thing

Attachment:

AriMB 06 Feb 2013 20:17
AriMB

Included page "member:arimb" does not exist (create it now)


Guest

Oops…i forgot to login. The above post is mine

Attachment:

AnonymousBoba Foxx 06 Feb 2013 23:46
Anonymous

Included page "member:anonymous" does not exist (create it now)

Boba Foxx
Guest

It looks like what you're doing is inverted binary (instead of 1 being on and 0 being off, you have 1 represent off and 0 be on).
The code I wrote allows you to input a 5 character string of 1's and 0's and it inverts it to give the intended answer (as you said, 11111 is A).

Attachment:

AnonymousBoba Foxx 06 Feb 2013 23:49
Anonymous

Included page "member:anonymous" does not exist (create it now)

Boba Foxx
Guest

Another correction (I really should get into the habit of testing my code more since I haven't written much recently >.>

:If X<5 or X=31
:Stop
:Sub("ABCDEFGHIJKLMNOPQRSTUVWXYZ",X,1

should be

:If X<4
:Stop
:output(2,1,Sub("ABCDEFGHIJKLMNOPQRSTUVWXYZ",32-X,1

Attachment:

AriMB 07 Feb 2013 17:22
AriMB

Included page "member:arimb" does not exist (create it now)


Guest

clarification:
what i meant would look something like this

[input]

[divide string into segments of 5]

[compare segments of 5 to 11111 (A) all the way to 00110 (Z)]
       A:11111
       B:11110
       C:11101
...11100,11011,11010,11001,11000,10111,10110,10101,10100,10011,10010,10001,10000,01111,01110,01101,01100,01011,01010,01001,01000,00111,00110

[add new letter to existing string]

[output string once done]

Attachment:

Xeda Elnara 07 Feb 2013 19:56
Xeda Elnara

Moderator

FA

Guest
.2length(Str1→B
For(A,1,B
0
For(C,-4,0
2Ans+expr(sub(Str1,5A+C,1
End
Str1+sub("ZYXWVUTSRQPONMLKJIHGFEDCBA",Ans-5,1→Str1
End

I am sure there is a faster and smaller way, but I think that works (I didn't test it).

Attachment:

AriMB 08 Feb 2013 17:51
AriMB

Included page "member:arimb" does not exist (create it now)


Guest

Xeda Elnara's code works, but it adds the answer to the end of the input. how could that be fixed?

Attachment:

Anonymous 08 Feb 2013 20:43
Anonymous

Included page "member:anonymous" does not exist (create it now)


Guest
" →  Str0
.2length(Str1→B
For(A,1,B
0
For(C,-4,0
2Ans+expr(sub(Str1,5A+C,1
End
Str0+sub("ZYXWVUTSRQPONMLKJIHGFEDCBA",Ans-5,1→Str0
End

It stores it to Str0.

Attachment:

Xeda Elnara 08 Feb 2013 21:03
Xeda Elnara

Moderator

FA

Guest

Oh, sorry, I misread something and thought that you wanted it at the end of the string, sorry. You could add this to the end of my code to remedy that:

sub(Ans,5B+1,int(B

My code assumes that the input might not be a multiple of 5 digits.

Attachment:

Make a reply:

To use the style buttons, click on the one you want, then press Ctrl+V.


Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License