LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 06-24-2012, 04:21 AM   #1
mscoder
LQ Newbie
 
Registered: Jun 2011
Posts: 18

Rep: Reputation: Disabled
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..
 
Old 06-24-2012, 04:29 AM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728
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?
 
Old 06-24-2012, 05:20 AM   #3
pan64
Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 5,024

Rep: Reputation: 1324Reputation: 1324Reputation: 1324Reputation: 1324Reputation: 1324Reputation: 1324Reputation: 1324Reputation: 1324Reputation: 1324Reputation: 1324
do you have a preferred language (perl, awk, c++ or ?)
 
Old 06-24-2012, 08:24 AM   #4
mscoder
LQ Newbie
 
Registered: Jun 2011
Posts: 18

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by pixellany View Post
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?
sorry for not clearing it in the last post..but by adding i mean adding the two hexadecimal numbers stored in the two lists...the final list shoud contin the addition of two numbers in hexadecimal format.
 
Old 06-24-2012, 08:39 AM   #5
dwhitney67
Senior Member
 
Registered: Jun 2006
Location: Maryland
Distribution: Kubuntu, Fedora, RHEL
Posts: 1,523

Rep: Reputation: 332Reputation: 332Reputation: 332Reputation: 332
Quote:
Originally Posted by mscoder View Post
sorry for not clearing it in the last post..but by adding i mean adding the two hexadecimal numbers stored in the two lists...the final list shoud contin the addition of two numbers in hexadecimal format.
Still not clear is what programming language you are using.

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.

Last edited by dwhitney67; 06-24-2012 at 08:41 AM.
 
Old 06-24-2012, 08:49 AM   #6
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
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.
 
1 members found this post helpful.
  


Reply

Tags
list


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Linked list C exvor Programming 14 06-22-2007 07:06 PM
linked list traversal Deepak Inbasekaran Programming 3 05-16-2007 11:33 PM
Linked list manas_sem Programming 3 12-21-2006 02:53 AM
C linked list exvor Programming 4 04-28-2006 06:25 AM
linked list + c dilberim82 Programming 5 05-05-2005 12:48 AM


All times are GMT -5. The time now is 06:50 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration