hexadecimal linked list
i came across a problem of adding 2 hexadecimal linked lists but i can't understand how to implement list where both alphabets and integer characters are stored..
help me wid the code of the same pls.. |
Please post a sample of what the data looks like, and what you want the output to look like.
When you say "adding two lists", do you mean that you want to add pairs of hex values, or maybe just combine the lists? |
do you have a preferred language (perl, awk, c++ or ?)
|
Quote:
|
Quote:
However, as far as the storage of the hex data, store it as a string of character(s). All symbols are characters, unless you opt to treat them otherwise. So "8F" is composed of the characters '8' and 'F' (and the terminating NULL character). To perform addition of the hex data, you will need to convert the string to a number; for example, for "8F", you would convert the '8' to the number 8 and multiply by 16; for the 'F', convert this to 15 and add to the previous multiplication result. Repeat for the other value, then perform the addition of the two values. When done, reconvert to the result to a hex string representation. In summary (pseudocode): Code:
hexStrResult = ConvertToHexString( ConvertToNumber(hexStr1) + ConvertToNumber(hexStr2) ) P.S. Conversely, you can store all data as numbers, and only display the data in hex when requested to print the values of the linked list. This might be the easier approach. |
So if I understand correctly the problem boils down to adding two numbers which are held as a string and in hexadecimal representation.
So you may need a loop (to step through each character in the string, starting with from the right, the least significant digit) {If the point of the list is to hold a single character then this is not required} Take each character and any carry digit and add the three together Convert each digit to a number If the three values are greater than 16 the subtract 16 and add a carry digit Convert the total back to a character The functions that will convert back and forth from number to character can be simple switch statement There is the basic design for you. Now implement in your selected language, test and find any errors or omissions. ;) |
All times are GMT -5. The time now is 01:40 AM. |