Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

unsigned char to String

Posted on 2006-05-17
2
Medium Priority
?
787 Views
Last Modified: 2008-02-01
HI
  I want to combine the unsigned char into a string array, how can I do that?  


void outputMAC(unsigned char MAC[])
{
 
    printf("Your MAC Address Is: %02X-%02X-%02X-%02X-%02X-%02X", MAC[0], MAC[1], MAC[2], MAC[3], MAC[4], MAC[5]);
//       finalmac=MAC[0]+MAC[1]+MAC[2]+MAC[3]+MAC[4]+MAC[5];

}

MAC[0]=00 in HEX
MAC[1]=04 in HEX
MAC[2]=75 in HEX
MAC[2]=82 in HEX
MAC[2]=26 in HEX
MAC[2]=EA in HEX

how can I reformat them into array that store "0004758226EA" into arrary

because i need to perform xor with another array

a[0]=1
a[1]=6
a[2]=4
a[3]=A
etc...

0 0 0 4
1 6 4 A   xor
---------------

Pls help

0
Comment
Question by:goretti
  • 2
2 Comments
 
LVL 8

Accepted Solution

by:
Knut Hunstad earned 80 total points
ID: 16716715
I'm not sure if I really see what you mean, but doing:

 sprintf(TheString, "%02X%02X%02X%02X%02X%02X", MAC[0], MAC[1], MAC[2], MAC[3], MAC[4], MAC[5]);

should set TheString to "0004758226EA". What is the declaration of your a array? Note that if you want:

7 xor 5 to become 2   (111 xor 101 -> 010)

you can't use:

"7" xor "5" as strings, because the ascii code for "7" is 55, so you will be doing:

55 xor 53 and getting 6 (100101 xor 100011 -> 000110)

I think what you need might be some shift operations to separate the 2 digit MAC values into single digit values:

NewMac[0] = Mac[0] >> 4;
NewMac[1] = Mac[0] - NewMac[0] << 4;
NewMac[2] = Mac[1] >> 4;
NewMac[3] = Mac[1] - NewMac[2] << 4;
...

or even quicker, add the a values instead:

NewA[0] = a[0] << 4 + a[1];
NewA[1] = a[2] << 4 + a[3];

Hope this helps you along! If not, explain a little more what you want to do. It's always easier to get a good answer when you write exactly what you need to _do_, not only your idea of how to approach it :-) For this question, that would mean telling exactly what kind of result you need and possibly also what you will be using it for next...
0
 
LVL 8

Expert Comment

by:Knut Hunstad
ID: 16718087
I just realized this question is a continuation of http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/VisualC_PLUS_PLUS_DOT_NET/Q_21853382.html, would have been nice if you pointed that out in your question :-)

For the exact problem you adress there, I think:

sprintf(TheResult, "%01X%02X", (MAC[4] & 0xF)^rgValue[9], MAC[5]^(rgValue[10] << 4 + rgValue[11]));

is quite efficient, but maybe not so easy to follow at first glance...
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
In Easy String Encryption Using CryptoAPI in C++ (http://www.experts-exchange.com/viewArticle.jsp?aid=1193) I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
The Relationships Diagram is a good way to get an overall view of what a database is keeping track of. It is also where relationships are defined. A relationship specifies how two tables connect to each other. As you build tables in Microsoft Ac…
Suggested Courses
Course of the Month13 days, 15 hours left to enroll

581 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question