Computer Science Canada Hex and Bin conversion. |
Author: | Justin_ [ Thu Feb 16, 2006 12:10 am ] | ||||||
Post subject: | Hex and Bin conversion. | ||||||
Nothing special, but my first submission ![]() Will continue to update and add more features to the class as I think of them and as I learn more about c++. comments are welcome. (if i'm doing something bad let me know.) hex.h
hex.cpp
Example:
|
Author: | md [ Thu Feb 16, 2006 12:13 am ] |
Post subject: | |
Your to binary function definitely doesn't work ![]() And why is this a class? It's much better written as a couple of functions... |
Author: | Justin_ [ Thu Feb 16, 2006 12:24 am ] |
Post subject: | |
how doesn't it work? And in the near future you'll see why its in a class ![]() |
Author: | wtd [ Thu Feb 16, 2006 1:07 am ] | ||
Post subject: | |||
Wow... that binary conversion function is excruciatingly complex for no good reason. Now, I won't give you the code outright in C++, but I will show it to you in O'Caml. ![]()
|
Author: | Justin_ [ Thu Feb 16, 2006 9:57 am ] |
Post subject: | |
It wasn't hard to make, just tedious. I hate repetition but a solid algorithm wasn't coming to mind immediately so I decided to do it the obvious way. Of course, that function only took less than ten minutes to make because I copied and pasted the first line and just filled in all the rest with the appropriate numbers. For enrichment purposes I will likely design my own algorithm to make it sweeter. |
Author: | Justin_ [ Thu Feb 16, 2006 10:58 am ] |
Post subject: | |
Cornflake wrote: Your to binary function definitely doesn't work I believe you are definitely wrong. I'm adding an updated version anyway, but please note I haven't changed the toBin() function. |
Author: | md [ Thu Feb 16, 2006 2:53 pm ] |
Post subject: | |
Here's why it doesn't work: 0x00 is 2#00000000. Your code makes it 2#00. a hex digit is always 4 digits of binary. Strange how wtd missed that one... |
Author: | rizzix [ Thu Feb 16, 2006 4:17 pm ] |
Post subject: | |
Cornflake wrote: a hex digit is always 4 digits of binary. Strange how wtd missed that one...
Not really. Well what you are talking about is bits/bytes in memory (hardware stuff). He's talking about the binary number system (math, not hardware). ![]() |
Author: | Justin_ [ Thu Feb 16, 2006 4:17 pm ] |
Post subject: | |
a hex digit can be represented with 4 digits of binary true, but a binary digit isn't always four digits. For instance: 0 in binary is 0 in decimal. I can see what you are saying though, considering I used hex to convert to binary. It's just that converting from hex to binary is much easier than converting decimal to binary. If I knew of an easier way I would have used it. |
Author: | avok23 [ Mon May 05, 2008 8:44 pm ] |
Post subject: | |
md @ Thu Feb 16, 2006 12:13 am wrote: Your to binary function definitely doesn't work
![]() And why is this a class? It's much better written as a couple of functions... i think he was trying to create an interface like the type you get in managed languages c# and java Math.Sin( angle ); just in case u have a function with that name. i would probably use a namespace instead |