"news.hku.hk" wrote:[color=blue]
>
> Sorry, just now i typed my question wrongly,
> the output of od -t x1 myfile.bin should be:
>
> 0000000 7f 45 4c 46 01 02 01 00 00 00 2f 75 73 72 2f 6c
> 0000020 12 13 7f 82
>
> also, the content of the buffer is given.........that means i can't change
> its content
> when i open the test.bin with notepad, the output would be in unreadable
> form
> also, i've tried the write member of out stream, but it simply copies what i
> have in the buffer to test.bin which isn't wanted. Could you help me again,
> thanks a lot ![/color]
Start with breaking the string into pieces.
You can't do what you want to do as long as you have
"7f 45 4c 46 01 02 01 00 00 00 2f 75 73 72 2f 6c 12 13 7f 82"
You need to break this string into parts:
"7f"
"45"
"4c"
"46"
...
once that part is done, you create an unsigned char from the textual
representation:
"7f" -> 7 * 16 + 15 -> 127 'writing' 127 to the output stream gives a hex value of 0x7f
"45" -> 4 * 16 + 5 -> 69 'writing' 69 to the output stream gives a hex value of 0x45
"4c" -> 4 * 16 + 12 -> 76 'writing' 76 to the output stream gives a hex value of 0x4c
"46" -> 4 * 16 + 6 -> 70 'writing' 70 -"- 0x46
...
For this you need to seperate each string into the individual characters and recode them into
numbers:
'0' -> 0
'1' -> 1
'2' -> 2
...
'9' -> 9
'a' -> 10
'A' -> 11
'b' -> 12
'B' -> 12
...
'f' -> 15
'F' -> 15
(Note: some of the stream functionalities in conjunction with a string stream could
be handy. If you don't want to use this, then a function doing the conversion is
an easy exercise to do).
--
Karl Heinz Buchegger
kbuchegg@gascad.at