1. hello, i also have some conversion problems.

input:

char InBuff[8] = "12345678";

output:

char OutBuff[6] should be '123456' first 6 digits
char OutB should be '78' last 2 digits (bcd encoded)

the implementation should be a one liner.this is what a have so far.it works, aslong no 0 is involved

OutB = ((InBuff[6] - 0x30) * 10) + (InBuff[7] - 0x30);

can anyone help me out here and show me a good implementation or give me some hints plz.

2. It looks like it should work, though it would be better to write:
Code:
`OutB = ((InBuff[6] - '0') * 10) + (InBuff[7] - '0');`
How does it not work?

3. thx, i thought there is no difference between them.i need to read this again.

ok it does not work if we have a zero at the first position of the last 2 bytes.

lets say we have this:

incoming buffer "12345608"

now the outgoing char value should be "08", but this impementation returns "8". thats the problem i need to solve.

4. now the outgoing char value should be "08", but this impementation returns "8". thats the problem i need to solve.
Oh. This is just a formatting problem. You may need to write:
Code:
`printf("&#37;02d\n", OutB);`

5. Code:
`char InBuff[8] = "12345678";`
"12345678" is a string literal. It's actually 9 characters long "12345678" <- your string + '\0' null terminator. So basically you have an array bounds overflow. It should be:
Code:
`char InBuff[9] = "12345678";`

6. hmm, does that mean i can use some printf family functionallity to store the data in a char. ok i will try it and post the result later on.

thx Brad, you are absolutely right. but i do not use a literal, the buffer array is dynamically allocated, and then filled with (fixed length) data without null termination.

7. does that mean i can use some printf family functionallity to store the data in a char
No. The value stored in the char is 8. Whether you print it as 0 or as 08 is another matter. If you want to store "08", then you cannot use a char, but an array of chars.

8. ok, thanks laserlight. i see this isnt as trivial as i thought. looks like i need to get rid of the oneline idea, cause i do not have any other option then 1 single char.

9. Originally Posted by Mr.Bit
hello, i also have some conversion problems.

input:

char InBuff[8] = "12345678";

output:

char OutBuff[6] should be '123456' first 6 digits
char OutB should be '78' last 2 digits (bcd encoded)

the implementation should be a one liner.this is what a have so far.it works, aslong no 0 is involved
You want to rip the last two characters of the string InBuff in a variable named OutB in a
one-liner statement? That is not so hard actually, just strcpy, memcpy whatever starting at 2 places befor the end of InBuff.
The end of InBuff can be found by adding to the address where InBuff starts it's string length. That is the character that terminates InBuff, which contains a '\0'. Now just remove 2, and there is your place.
Then strcpy, or memcpy from that location whatever is your choice. Cause as you said, if it is say '08' the conversion to a number will kill your 0, but you want it am i correct?
If that is the case it can be easily done in one line, by just performing all the calculation for the appropriate offset at the parameter of the copying function.

10. yes, you are correct.i need the exact same value in this char, even if its '00'.

im not sure if i fully understand, however i will try it and post the result later on. i need to go home now, its about 11 oclock and im still at the office!