Interesting conversion from Dec to Hex

I recording an input from another device and the number it gives me is in Dec. form and I need it in Hex. But here is the interesting thing about it I need it in a special form.

Here is what I have

char Input

Input = 270113178514024717

I need it split like this

x = 2972226931
y = 15881851
where the hex will look like this

x = B1289573
y = F2567B

and store it in an output like this

char Output

Output = B1289573F2567B

My input will always be the same size but just different numbers and my Output needs to be the same size as shown here also.

Thanks

How do you get :

x = 2972226931
y = 15881851

from:

Input = 270113178514024717

?

The other part of the problem can be solved like this:

int x = 2972226931;
int y = 15881851;

char hex_join[32];
sprintf( hex_join, "%X%X", x, y );

Sorry the Input number should be

char Input

Input = 297222693115881851

I was pulled the wrong number from a read out I had.

How do you know where to split it? Also wouldn't this be much easier to send as raw bytes? It'll be much simpler than messing around with ASCII conversions and guessing where to split it.

It needs to be split after the first 10 chars.

I am calling out to another device and it is coming back as a Dec. number but I need to print it out of a printer showing it in Hex form.

most of the devices I call to send it back in Hex from already and the output is in the format I need just to stright print.

But I have just one so far that decided it wanted to be different and give me the output in Dec. form.

Try this:

// Your code that puts the DEC number into input, ie 297222693115881851 should replace the below line .
strcpy( input, "297222693115881851" );

char cpy_char = input[10];
input[10] = 0;
unsigned long x = strtoul( input, NULL, 10 );
input[10] = cpy_char;
unsigned long y = strtoul( &input[10], NULL, 10 );

// we now have x and y as numerical values.
// Joint them as a hex string ...

char hex_join[32];
sprintf( hex_join, "%X%X", x, y );

// hex_join now contains the joined numbers in hex ...