Thread: concatenate hex numbers

  1. #1
    Registered User
    Join Date
    Nov 2010
    Posts
    4

    concatenate hex numbers

    Hi guys,

    I am new to C++ and had a question.

    I have a table of 4-digit hex numbers in each row and I want to go through the table, choose row1 and row2 and concatenate the 4-digit hex numbers into an 8-digit hex number.

    For example, I have 0x123A in row1 and 0x45BC in row2 of the table. I want to to get 0x123A45BC and compare it to another 8-digit user input hex number.

    How would I go about doing this? srtcat and strcmp?

    By the way, the hex numbers in the table are mapped to locations D000-D3FF in a hard disk. Meaning that row1 (4 digit hex) is in location D000 and row2 is in D001 and so on.
    So maybe I could concate the memory locations and then compare them to the user input?

    I would appreciate any help,

    Thanks,
    Ryan

  2. #2
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Quote Originally Posted by ryanE View Post
    For example, I have 0x123A in row1 and 0x45BC in row2 of the table. I want to to get 0x123A45BC and compare it to another 8-digit user input hex number.

    How would I go about doing this? srtcat and strcmp?
    It depends on how they are stored. Are they strings? Or is this table something like an actual const array of ints?
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  3. #3
    Registered User
    Join Date
    Nov 2010
    Posts
    4
    Thanks for the reply.

    The table is actually stored with hex constants all throughout.
    e.g. the first row is "123A" (memory location D000), second row is 45BC (mem loc D001) and so on.

  4. #4
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,613
    Well if I did this in decimal math, then:

    a = 1234, b = 5678;
    a = a * 10^4
    a = a + b

    It's the same thing in a different base.

  5. #5
    Registered User
    Join Date
    Nov 2010
    Posts
    4
    Quote Originally Posted by whiteflags View Post
    Well if I did this in decimal math, then:

    a = 1234, b = 5678;
    a = a * 10^4
    a = a + b

    It's the same thing in a different base.
    Thanks for the reply,

    Sure that would work for the concate part. So after I concate the two 4-digit hex numbers from the table how would I compare it with an 8-digit hex user input?
    Last edited by ryanE; 11-08-2010 at 01:25 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. divide 2 hex numbers
    By dust555 in forum C Programming
    Replies: 5
    Last Post: 04-15-2007, 11:20 PM
  2. Writing unique numbers to an array
    By yardy in forum C Programming
    Replies: 6
    Last Post: 12-27-2006, 09:15 PM
  3. Replies: 3
    Last Post: 01-23-2006, 07:25 PM
  4. converting hex to dec
    By jibbles in forum C Programming
    Replies: 20
    Last Post: 08-07-2004, 11:40 PM
  5. A (complex) question on numbers
    By Unregistered in forum C++ Programming
    Replies: 8
    Last Post: 02-03-2002, 06:38 PM

Tags for this Thread