From: Andy Shevchenko <andy.shevchenko@gmail.com>
To: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Cc: Andy Shevchenko <ext-andriy.shevchenko@nokia.com>
Subject: [PATCH 05/12] lib: introduce common method to convert hex digits
Date: Thu, 18 Feb 2010 20:55:44 +0200 [thread overview]
Message-ID: <1266519351-3218-6-git-send-email-andy.shevchenko@gmail.com> (raw)
In-Reply-To: <1266519351-3218-5-git-send-email-andy.shevchenko@gmail.com>
From: Andy Shevchenko <ext-andriy.shevchenko@nokia.com>
hex_to_bin() is a little method which converts hex digit to its actual value.
There are plenty of places where such functionality is needed.
Signed-off-by: Andy Shevchenko <ext-andriy.shevchenko@nokia.com>
---
include/linux/kernel.h | 2 ++
lib/hexdump.c | 19 +++++++++++++++++++
2 files changed, 21 insertions(+), 0 deletions(-)
diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index 328bca6..bbbf885 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -361,6 +361,8 @@ static inline char *pack_hex_byte(char *buf, u8 byte)
return buf;
}
+extern int hex_to_bin(char ch);
+
#ifndef pr_fmt
#define pr_fmt(fmt) fmt
#endif
diff --git a/lib/hexdump.c b/lib/hexdump.c
index 39af256..d79b166 100644
--- a/lib/hexdump.c
+++ b/lib/hexdump.c
@@ -16,6 +16,25 @@ const char hex_asc[] = "0123456789abcdef";
EXPORT_SYMBOL(hex_asc);
/**
+ * hex_to_bin - convert a hex digit to its real value
+ * @ch: ascii character represents hex digit
+ *
+ * hex_to_bin() converts one hex digit to its actual value or -1 in case of bad
+ * input.
+ */
+int hex_to_bin(char ch)
+{
+ if ((ch >= 'a') && (ch <= 'f'))
+ return ch - 'a' + 10;
+ if ((ch >= '0') && (ch <= '9'))
+ return ch - '0';
+ if ((ch >= 'A') && (ch <= 'F'))
+ return ch - 'A' + 10;
+ return -1;
+}
+EXPORT_SYMBOL(hex_to_bin);
+
+/**
* hex_dump_to_buffer - convert a blob of data to "hex ASCII" in memory
* @buf: data blob to dump
* @len: number of bytes in the @buf
--
1.5.6.5
next prev parent reply other threads:[~2010-02-18 18:58 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-02-18 18:55 [PATCH 00/12] Clean up code to use native kernel functions when convert or check " Andy Shevchenko
2010-02-18 18:55 ` [PATCH 01/12] isdn: remove ishexdigit() in regard to isxdigit() Andy Shevchenko
2010-02-18 18:55 ` [PATCH 02/12] audit: use kernel's method to get byte in hex form Andy Shevchenko
2010-02-18 18:55 ` [PATCH 03/12] staging: remove unused methods Andy Shevchenko
2010-02-18 18:55 ` [PATCH 04/12] scsi: ibmmca: use kernel native convertor Andy Shevchenko
2010-02-18 18:55 ` Andy Shevchenko [this message]
2010-02-18 18:55 ` [PATCH 06/12] drivers: net: optimize hex2bin() Andy Shevchenko
2010-02-18 18:55 ` [PATCH 07/12] usb: atm: speedtch: use new hex_to_bin() method Andy Shevchenko
2010-02-18 18:55 ` [PATCH 08/12] net: " Andy Shevchenko
2010-02-18 18:55 ` [PATCH 09/12] drivers: net: use kernel's method to get byte in hex form Andy Shevchenko
2010-02-18 18:55 ` [PATCH 10/12] drivers: net: use new hex_to_bin() method Andy Shevchenko
2010-02-18 18:55 ` [PATCH 11/12] drivers: isdn: " Andy Shevchenko
2010-02-18 18:55 ` [PATCH 12/12] drivers: wireless: use kernel's method to get byte in hex form Andy Shevchenko
2010-02-18 23:55 ` [PATCH 11/12] drivers: isdn: use new hex_to_bin() method Tilman Schmidt
2010-02-19 9:53 ` [PATCHv2] " Andy Shevchenko
2010-02-19 14:53 ` [PATCH 03/12] staging: remove unused methods Greg KH
2010-02-22 20:21 ` [PATCH 02/12] audit: use kernel's method to get byte in hex form Eric Paris
2010-02-22 21:18 ` Andy Shevchenko
2010-02-18 23:36 ` [PATCH 01/12] isdn: remove ishexdigit() in regard to isxdigit() Tilman Schmidt
2010-02-19 11:41 ` [PATCH 00/12] Clean up code to use native kernel functions when convert or check hex digits Andy Shevchenko
2010-02-19 23:44 ` Tilman Schmidt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1266519351-3218-6-git-send-email-andy.shevchenko@gmail.com \
--to=andy.shevchenko@gmail.com \
--cc=ext-andriy.shevchenko@nokia.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome