LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices


Reply
  Search this Thread
Old 12-20-2010, 03:53 PM   #1
ano
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 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
 
Old 12-21-2010, 01:09 AM   #2
JZL240I-U
Senior Member
 
Registered: Apr 2003
Location: Germany
Distribution: openSuSE Tumbleweed-KDE, Mint 21, MX-21, Manjaro
Posts: 4,629

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 03:31 AM.
 
1 members found this post helpful.
Old 12-21-2010, 09:04 AM   #3
cnxsoft
Member
 
Registered: Nov 2010
Location: Thailand
Distribution: Fedora 12, Ubuntu 10.10
Posts: 167

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, 10:52 AM   #4
ano
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
 
  


Reply



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 11:17 AM
can any one list all the methods for converting dec->Hex telnet_ping Programming 2 09-13-2007 11:41 PM
converting a hex file to binary linx win Programming 3 07-20-2006 03:04 AM
C, converting hex to text Sm0k3 Programming 2 10-11-2003 04:29 AM
converting fake hex to decimal in c acid_kewpie Programming 10 08-20-2003 02:29 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 01:39 AM.

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