Computer Science Canada Hex to Decimal Converter |
Author: | Alucard [ Mon Dec 11, 2006 1:11 pm ] |
Post subject: | Hex to Decimal Converter |
I am totally lost with my hex to decimal converter. I have no idea how to do it, can anyone help? Even if it is how to do it in another language, I could probably figure it out. Here is what I got, it will work, but only with 1 hex number. put "Enter your hexidecimal number, and I will convert it to decimal." get hextodec for decreasing n : length (hextodec) .. 1 if hextodec (n) = '0' then decout := decout + 0 elsif hextodec (n) = '1' then decout := decout + 1 elsif hextodec (n) = '2' then decout := decout + 2 elsif hextodec (n) = '3' then decout := decout + 3 elsif hextodec (n) = '4' then decout := decout + 4 elsif hextodec (n) = '5' then decout := decout + 5 elsif hextodec (n) = '6' then decout := decout + 6 elsif hextodec (n) = '7' then decout := decout + 7 elsif hextodec (n) = '8' then decout := decout + 8 elsif hextodec (n) = '9' then decout := decout + 9 elsif hextodec (n) = 'A' then decout := decout + 10 elsif hextodec (n) = 'B' then decout := decout + 11 elsif hextodec (n) = 'C' then decout := decout + 12 elsif hextodec (n) = 'D' then decout := decout + 13 elsif hextodec (n) = 'E' then decout := decout + 14 elsif hextodec (n) = 'F' then decout := decout + 15 end if end for put "Your decimal number is: ", decout end if decout := 0 |
Author: | wtd [ Mon Dec 11, 2006 1:29 pm ] | ||
Post subject: | |||
You know, there's a way to convert a string to a number, and to test if a string is a number. You may wish to employ this existing functionality. ![]() |
Author: | AndrewJ [ Tue Dec 12, 2006 8:17 pm ] |
Post subject: | |
my suggestion would be to use a function rather than typing all that code out start like this... function hex_to_dec (hex:int):int var n :int . . . . and so on if you dont understand the process of function i would suggest using turing help (F10) or ask someone you know who is quite experienced as the help window can somtimes be confusing...[/b] |
Author: | Matterialize [ Fri Dec 15, 2006 5:41 pm ] | ||||
Post subject: | |||||
Use this.
Assuming "hexin" is your inputting Hex number, and "decout" is the Decimal output. It'll convert any Hex number into decimal. ![]() You need to preset "decout" to 0, though. If you want to repeat the conversion in the same run of the program, you need to set it back to 0 again, like this:
[/code] |
Author: | vapour99 [ Tue Nov 04, 2008 8:24 pm ] | ||||
Post subject: | |||||
Matterialize @ Fri Dec 15, 2006 5:41 pm wrote: Use this.
Assuming "hexin" is your inputting Hex number, and "decout" is the Decimal output. It'll convert any Hex number into decimal. ![]() You need to preset "decout" to 0, though. If you want to repeat the conversion in the same run of the program, you need to set it back to 0 again, like this:
[/code] That is a very easy way to convert hex to decimal! thank-you very much for that syntax. the only issue is that i dont want to use that little bit of code in my converter program if i dont understand how it works. Could you explain the inner workings of it to me? |
Author: | Insectoid [ Tue Nov 04, 2008 8:56 pm ] |
Post subject: | RE:Hex to Decimal Converter |
Necroing is frowned upon. This thread is 2 years old. The original poster has not posted since then. This is a dead thread. Look at the date of the last post before submitting your own. |
Author: | BaddiePayve.HxC [ Wed Nov 12, 2008 7:54 pm ] |
Post subject: | Re: RE:Hex to Decimal Converter |
insectoid @ Tue Nov 04, 2008 8:56 pm wrote: Necroing is frowned upon. This thread is 2 years old. The original poster has not posted since then. This is a dead thread. Look at the date of the last post before submitting your own.
Oh please. It's turing forums on compsci. Plus he had something legit to say. I would hardly call that necroing. |
Author: | [Gandalf] [ Wed Nov 12, 2008 8:02 pm ] |
Post subject: | Re: RE:Hex to Decimal Converter |
BaddiePayve.HxC @ 2008-11-12, 7:54 pm wrote: Oh please. It's turing forums on compsci. Plus he had something legit to say. I would hardly call that necroing.
While I agree more than most that some posts in old topics shouldn't qualify as necro-posts, this post doesn't really qualify. He's basically saying "thanks and could you explain your program?" From the rules we have: Quote: Necro Posting
Posting in old topics is generally frowned upon, unless the post is really important and relevant. If your post is important (for example, say you made a big improvement to an algorithm the original author was using), you may post in an otherwise dead topic. However, bringing up an old game from [Turing Source Code] to say, "Good job!" is necro posting, and you will be yelled at. Whether a thread is considered dead or not largely depends on the forum. Posts in [Turing Help] have a very short lifespan, so even a useless post in a week-old thread could be necro posting. Realize that, for a lot of old topics, the original author is no longer an active user on the site, in which case (s)he will not get your message. If you had to go trolling through a page of threads or more to find the topic, it's a safe bet that you shouldn't be posting in it. |
Author: | BaddiePayve.HxC [ Wed Nov 12, 2008 8:47 pm ] |
Post subject: | Re: RE:Hex to Decimal Converter |
[quote="[Gandalf] @ Wed Nov 12, 2008 8:02 pm"] BaddiePayve.HxC @ 2008-11-12, 7:54 pm wrote: Oh please. It's turing forums on compsci. Plus he had something legit to say. I would hardly call that necroing.
While I agree more than most that some posts in old topics shouldn't qualify as necro-posts, this post doesn't really qualify. He's basically saying "thanks and could you explain your program?" From the rules we have: Quote: Necro Posting
[/quote]
Posting in old topics is generally frowned upon, unless the post is really important and relevant. If your post is important (for example, say you made a big improvement to an algorithm the original author was using), you may post in an otherwise dead topic. However, bringing up an old game from [Turing Source Code] to say, "Good job!" is necro posting, and you will be yelled at. Whether a thread is considered dead or not largely depends on the forum. Posts in [Turing Help] have a very short lifespan, so even a useless post in a week-old thread could be necro posting. Realize that, for a lot of old topics, the original author is no longer an active user on the site, in which case (s)he will not get your message. If you had to go trolling through a page of threads or more to find the topic, it's a safe bet that you shouldn't be posting in it. I 'spose. But it can't be taken THAT seriously, can it? |
Author: | [Gandalf] [ Wed Nov 12, 2008 8:54 pm ] |
Post subject: | RE:Hex to Decimal Converter |
Rules are rules, and as far as I'm aware aren't up for discussion. No? Was hoping not to lock this, but so it must be. ![]() |