Computer Science Canada Graphic LEDs to display Binary? |
Author: | mapleleaf31 [ Wed Jan 19, 2005 4:32 pm ] | ||
Post subject: | Graphic LEDs to display Binary? | ||
Ok so I'm making a program where I need to convert any character to ASCII and then to Binary and to display both of them, I have that written. The second part of it is too have 8 circles that are "LED"'s on the screen and have them fill to represent the Binary number, I can't figure out how to do the LED part SO far my code is...
Can anyone help me? |
Author: | Drakain Zeil [ Wed Jan 19, 2005 6:04 pm ] |
Post subject: | |
First you need to know how binary works... 1 - 1 2 - 10 3 - 11 4 - 100 5 - 101 6 - 110 7 - 111 8 - 1000 9 - 1001 10 - 1010 11 - 1011 12 - 1100 13 - 1101 14 - 1110 15 - 1111 ... I wrote somthing about it in my blong awhile back, if you want that I can find the link to the specific post, When I was younger I had a book on how to build one (hardware, out of some chips and whatnot), I could try and find that and post it up, doubt it would help with software however. Google might have somthing simmilar... Anyway, find out how binary works, that's first. Next, find out what the ascii letters are, how they work... Third, find out how to convert between decimal and binary. Once you have these, get the character, then use ord(character), convert this number to binary (actually, I think there's somthing in turring that does this for you, stringint or somthing like that), then depending on the location of each 1, turn on that light. |
Author: | mapleleaf31 [ Wed Jan 19, 2005 7:21 pm ] |
Post subject: | |
I know how binary works and I got how to convert it in the code up there, the thing I can't figure out is how to get Turing to recognize the new binary number and fill in the circles |
Author: | Neo [ Wed Jan 19, 2005 7:55 pm ] |
Post subject: | |
You'd want to use a for loop, each time you want to find the remainder, use mod 2, and store the value in a variable. If the remaind is 1 then fill in a circle. Then divide the number by 2. Repeat... |