Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Linux - Kernel This forum is for all discussion relating to the Linux kernel.


  Search this Thread
Old 12-20-2010, 04:53 PM   #1
LQ Newbie
Registered: Dec 2010
Posts: 9

Rep: Reputation: 0
Smile converting byte in hex in kernel

hi all first i'm newby programmer ....
I'm writing a module for linux kernel
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

Old 12-21-2010, 02:09 AM   #2
Senior Member
Registered: Apr 2003
Location: Germany
Distribution: openSuSE 42.1_64+Tumbleweed-KDE, Mint 17.3
Posts: 4,062

Rep: Reputation: Disabled
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 .

Last edited by JZL240I-U; 12-22-2010 at 04:31 AM.
1 members found this post helpful.
Old 12-21-2010, 10:04 AM   #3
Registered: Nov 2010
Location: Thailand
Distribution: Fedora 12, Ubuntu 10.10
Posts: 166

Rep: Reputation: 29
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.
Old 12-21-2010, 11:52 AM   #4
LQ Newbie
Registered: Dec 2010
Posts: 9

Original Poster
Rep: Reputation: 0
ok i have used simply memcpy(new_char_array,data+40,2);

tank you for the elucidation


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Hex values converting Inconsistently TheCrow33 Linux - General 2 12-20-2010 12:17 PM
can any one list all the methods for converting dec->Hex telnet_ping Programming 2 09-14-2007 12:41 AM
converting a hex file to binary linx win Programming 3 07-20-2006 04:04 AM
C, converting hex to text Sm0k3 Programming 2 10-11-2003 05:29 AM
converting fake hex to decimal in c acid_kewpie Programming 10 08-20-2003 03:29 PM > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 08:09 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration