converting byte in hex in kernel
hi all first i'm newby programmer ....
I'm writing a module for linux kernel 2.6.33.5 I have to read from an unsigned char array pointed by unsigned char *data_to_read=(unsigned char *)skb->data; where skb is a sock_buffer and data is a pointer unsigned char 2 byte (the [41] and the [42]), next i have to convert the readed value in hex and copy this value to another unsigned char array the question is also: what there is inside data_to_read[41] and [42]? how can i see ? because if the content is just hex i can use memcpy? any suggestion/indication will be apreciated tanks |
I do not understand the problem. All data are represented as bits organized in bytes. You can represent these bits in hexadecimal notation (for convenience, since numbers on the base of 16 lend themselves easily for the notation of values within two bytes (word in programming language "C") i.e. values between 0 and 65536 [2^16] in decimal notation).
Any conversion concerns data representation, not (byte)-values. As you stated your purpose you can simply copy the values over to that other array. Maybe I completely misunderstood. Then please re-state your problem :). |
I don't really understand what you try to achieve. If you just want to check the value of bytes 41 and 42 in your buffer and format them in hex just use printk.
printk("0x%x 0x%x\n", data_to_read[41], data_to_read[42]); To copy data from one buffer to the other, you can simply use mempcy as JZL240I-U indicated. |
ok i have used simply memcpy(new_char_array,data+40,2);
tank you for the elucidation :) |
All times are GMT -5. The time now is 04:44 AM. |