Computer Science Canada Binary to Hexadecimal |
Author: | braeden [ Fri Nov 14, 2008 1:01 pm ] | ||||
Post subject: | Binary to Hexadecimal | ||||
Here is a code i have to convert a binary number to hexadecimal. The code will not output anything if the there is more than 4 digits. It is part of a larger propgram that is due Monday. I have been working on this for 2 weeks. Help in getting it to work the correct way would be excellent.
Remember to use syntax tags. Thanks.
|
Author: | jbking [ Fri Nov 14, 2008 1:20 pm ] |
Post subject: | Re: Binary to Hexadecimal |
Are you familiar with div and mod operators? That is my suggestion to fix the problem you have. |
Author: | pavol [ Fri Nov 14, 2008 1:22 pm ] |
Post subject: | Re: Binary to Hexadecimal |
To start, your code doesn't output anything because you have an infinite loop: your main loop does not have any exit condition and so it runs forever and you never reach the end of your function. so you need somewhere in your loop something like exit when condition Also, since your code only checks the 16 cases that end with each distinct hex value, you cannot really take in a number like 10010 and give a correct output. Therefore, I don't suggest you add a bunch more elsif conditions to make your program work on a larger scale, but instead try to simplify your program a lot more by coming up with a more mathematical method on paper first and then implement it in your program. |
Author: | Chittle [ Fri Nov 21, 2008 8:32 pm ] | ||
Post subject: | Re: Binary to Hexadecimal | ||
Here this is what i came up with
|
Author: | Chittle [ Fri Nov 21, 2008 8:44 pm ] |
Post subject: | Re: Binary to Hexadecimal |
Oh sorry I guess this is a little late if it was due on monday... well there it is anyway. |