tags:

views:

127

answers:

1

I have one byte array which has some raw data like 1aa23486b2..and so on. I want to represent each byte in the array as a decimal number. I then have to go through the decimal numbers and pick out the first x decimal to output to screen.

if i use int byte [same size as input byte array] would that work? just declare and initialized it memset(byte,0,same size as input byte array];

then just loop through and copy it over which could do the trick but then how do i choose x amount of digits?

+2  A: 

What about using a printf statement to print the bytes as integers?

int numBytes = 5;
for (int i = 0; i < numBytes; i++)
{
    printf("%d ", &yourArray[i]);
}

printf("\n");
John at CashCommons
This, you could do the cast and length selection in the printf formatting.
Daniel Bingham
well the problem with printf was that when i used it and it returns the number values in the count i came across issues like..a2 it comes out to 162. this means that if i have another byte like 1b that would be 27. say if i wanted to print 6 and the next byte was 68 the decimal value of that hex would be 104. and i would end up only printing 16227 because 104 is more than 6 digits. see the issue?
djones2010
OK, I'm confused. You have the string "1aa23486b2" in your question. What is the output you want for this particular string of hex values?
John at CashCommons