Computer Science Canada How to make a pogram output TeXt LiKe ThIs |
Author: | zero44 [ Tue Sep 15, 2009 1:24 pm ] |
Post subject: | How to make a pogram output TeXt LiKe ThIs |
Im trying to make a program that can get a String of text then check if it is capital or lowercase for each go then change all the characters so the text come out like AbCdEfGhIJkLmNo. |
Author: | BigBear [ Tue Sep 15, 2009 1:45 pm ] |
Post subject: | RE:How to make a pogram output TeXt LiKe ThIs |
In the F10 Help under Turing Language Keystroke code how can u tell if a letter is lower case or upper case base on its ordinal value |
Author: | zero44 [ Tue Sep 15, 2009 2:32 pm ] | ||
Post subject: | Re: How to make a pogram output TeXt LiKe ThIs | ||
thx for the help but what i need to knw is what i can do to check if a number is odd or even would help i tried this but it doesn't help
|
Author: | Insectoid [ Tue Sep 15, 2009 2:50 pm ] |
Post subject: | RE:How to make a pogram output TeXt LiKe ThIs |
Every letter has a numerical value: It's ordinal value. This is it's ASCII code. Capital letters have different values than lower case letters. Iterate over each letter (with a for loop I would suggest) and use the ord() command to determine the value of the letter. From there you can figure it out yourself. |
Author: | BigBear [ Tue Sep 15, 2009 2:52 pm ] | ||||||||||
Post subject: | Re: How to make a pogram output TeXt LiKe ThIs | ||||||||||
The thing I wanted you to realize was check if it is less than or greater than 96 but to check if it is odd or even
First of all there is a few things
num is an integer because when you declared it you put
Integer means it can only be whole numbers real numbers can be decimal numbers and whole numbers for integers instead of using / for divided by you use div so
But you cannot say = int because int is a type You could use
|
Author: | zero44 [ Tue Sep 15, 2009 2:59 pm ] | ||
Post subject: | Re: How to make a pogram output TeXt LiKe ThIs | ||
every one thx for your help but these method seems to work perfectly
|
Author: | Insectoid [ Tue Sep 15, 2009 3:03 pm ] |
Post subject: | RE:How to make a pogram output TeXt LiKe ThIs |
So...did we answer your first question right or did you just switch questions? Re-reading the thread it looks like this: You: Hey I need help with this... Us: Have a look at this... You: Thanks, but all along I actually needed help with this other thing. |
Author: | zero44 [ Tue Sep 15, 2009 3:07 pm ] |
Post subject: | Re: How to make a pogram output TeXt LiKe ThIs |
ahh no i just forget to mention that i already know how to convert a capital to lowercase by adding 32 in ord but i need to figure out how to tell the computer which one to change and which one not to, so i was gonna do it by odds and evens so all the odd counts in string become caps and all the even become lowercase .... i hope i make sense.....having that said if anyone could help change the script so it comes out as boleen so if even true and if odd false? |
Author: | BigBear [ Tue Sep 15, 2009 3:12 pm ] |
Post subject: | RE:How to make a pogram output TeXt LiKe ThIs |
you are already checking if even or odd so just after you put "even" have a variable be assigned to true? |
Author: | zero44 [ Tue Sep 15, 2009 3:28 pm ] | ||||
Post subject: | Re: How to make a pogram output TeXt LiKe ThIs | ||||
ok this is what i have so far but it doesn't work need to fix 2 things the boleen and how to read what postion in loop the procces is at
BigBear i think i understand you i will try and reply EDIT: thx BigBear i fixed the boolean problem now i have
|
Author: | zero44 [ Tue Sep 15, 2009 4:03 pm ] | ||
Post subject: | Re: How to make a pogram output TeXt LiKe ThIs | ||
sry for double post but my last post was getting too big i have completed the program that i wished to right and it works successfully this is my first ever algorithm and im glad i got the help from you guys so thx for whoever wants to do something similar or has similar issues here is a script to compare with the old
|
Author: | btiffin [ Tue Sep 15, 2009 10:39 pm ] | ||
Post subject: | Re: How to make a pogram output TeXt LiKe ThIs | ||
old guy comment tests for even and odds; I don't know Turing syntax
The logical AND is usually a lot cheaper than modulus or division. Cheers |
Author: | Zren [ Tue Sep 15, 2009 11:04 pm ] | ||
Post subject: | Re: How to make a pogram output TeXt LiKe ThIs | ||
btiffin @ Tue Sep 15, 2009 10:39 pm wrote: old guy comment
tests for even and odds; I don't know Turing syntax
The logical AND is usually a lot cheaper than modulus or division. Cheers Mind explaining how the heck that works? or give a link. |
Author: | Euphoracle [ Tue Sep 15, 2009 11:09 pm ] |
Post subject: | RE:How to make a pogram output TeXt LiKe ThIs |
Well in binary, if something is odd it _has_ to have 2^0 (1). Therefore, any number represented in binary that has 2^0 as 1 is odd. You can apply this to your current problem. eg. 7 = 0111 <-- last bit is 2^0 = 1 = odd 6 = 0110 <-- last bit is 2^0 = 0 = even Rather than using the modulus operator, you can use this knowledge to cheaply check if something is odd. <var> AND 1 will return 1 if the 2^0 bit of <var> is 1 and 1 is 1 (which it is). If it is zero, it is even because the <var>'s 2^0 bit is not 1. |
Author: | Zren [ Tue Sep 15, 2009 11:40 pm ] |
Post subject: | Re: How to make a pogram output TeXt LiKe ThIs |
So if you changed 1 to a three, it would also look at 2^1 and compare that, then use an XAND between the two. So it would be true on 0,4,8,... I see, so it only looks at the digits in the smallest number. Funky. Thanks Euphoracle. |
Author: | zero44 [ Wed Sep 16, 2009 5:23 pm ] |
Post subject: | Re: RE:How to make a pogram output TeXt LiKe ThIs |
Euphoracle @ Wed Sep 16, 2009 4:09 am wrote: Well in binary, if something is odd it _has_ to have 2^0 (1). Therefore, any number represented in binary that has 2^0 as 1 is odd. You can apply this to your current problem.
eg. 7 = 0111 <-- last bit is 2^0 = 1 = odd 6 = 0110 <-- last bit is 2^0 = 0 = even Rather than using the modulus operator, you can use this knowledge to cheaply check if something is odd. <var> AND 1 will return 1 if the 2^0 bit of <var> is 1 and 1 is 1 (which it is). If it is zero, it is even because the <var>'s 2^0 bit is not 1. im a bit confused could you please write me a simple example |
Author: | DemonWasp [ Wed Sep 16, 2009 5:54 pm ] | ||
Post subject: | RE:How to make a pogram output TeXt LiKe ThIs | ||
When a number is written in binary, you can think of it as follows: Each bit has a "value". Bits that are 1 add that value to the total; bits that are 0 do not. Values increase from 1 with each subsequent bit having double the value of the previous one: 1, 2, 4, 8, 16, 32... Thus, the first few binary numbers are:
Notice a pattern? Numbers which are odd always have the "lowest" (last as drawn above) bit set to 1. This is because the only odd "bit value" is the first one - after that, they're all multiples of two, which is equivalent to being even. So if we take our number: 101000010101101 And bitwise-and it with 1: 000000000000001 We get 1 if the last bit of our number if 1 and 0 if the last bit of our number is zero. We can then test equality between that and the result. As it turns out, this is probably faster than doing the division (for reasons too complex to go into right now). An analogy to this would be divisors of 10. You know that a number is divisible by 10 if and only if it ends in 0. Numbers ending in 1-9 are NOT divisible by 10. In binary, numbers are divisble by 2 if and only if they end in 0; if they end in 1, they are not divisible by 2 (and therefore must be odd). |
Author: | btiffin [ Tue Sep 22, 2009 12:24 am ] |
Post subject: | RE:How to make a pogram output TeXt LiKe ThIs |
Excuse the late reply. Adding to Euphoracle's explanation with an old guy ramble. Zren, While you can, don't think of it as only looking at the digits in the smallest number. A one, 1, is actually 8 or more bits every time. It's just that the top 7 bits (or 31 for 32bit machines, etc...) are zeroes. Any bit, zero or one, when ANDed to a zero is zero. So AND 1 guarantees that you only care about the last bit. The low bit being a valid odd or even test. You either have a one added to the "rest" of the bits in the number, (odd) or zero (even). Only the low bit has this property, all the others are in positive powers of 2, so they are all even numbers, in whatever combination you throw them in. Only the lowly least significant bit gets to decide if you add that little bit of one to make an odd number. Cheers |