git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 1/3] notes: move hex_to_bytes() to hex.c and export it

From
René Scharfe <l.s.r@web.de>
Date
Nov 5, 2017, 16:47 UTC
Message-ID
<71257adb-56c0-2e13-c0b1-a7ee4b084207@web.de>
In-Reply-To
<20171105025647.GB23275@alpha.vpn.ikke.info>
Am 05.11.2017 um 03:56 schrieb Kevin Daudt:
Show 25 quoted lines
> On Tue, Oct 31, 2017 at 02:46:49PM +0100, René Scharfe wrote:
>> Make the function for converting pairs of hexadecimal digits to binary
>> available to other call sites.
>>
>> Signed-off-by: Rene Scharfe <l.s.r@web.de>
>> ---
>>   cache.h |  7 +++++++
>>   hex.c   | 12 ++++++++++++
>>   notes.c | 17 -----------------
>>   3 files changed, 19 insertions(+), 17 deletions(-)
>>
>> diff --git a/cache.h b/cache.h
>> index 6440e2bf21..f06bfbaf32 100644
>> --- a/cache.h
>> +++ b/cache.h
>> @@ -1317,6 +1317,13 @@ extern int set_disambiguate_hint_config(const char *var, const char *value);
>>   extern int get_sha1_hex(const char *hex, unsigned char *sha1);
>>   extern int get_oid_hex(const char *hex, struct object_id *sha1);
>>   
>> +/*
>> + * Read `len` pairs of hexadecimal digits from `hex` and write the
>> + * values to `binary` as `len` bytes. Return 0 on success, or -1 if
> 
> Is it correct to call the result binary? I would say that it's the value
> that gets stored. To me, this value does not really have a base.
Here's the full context:
  /*
   * Read `len` pairs of hexadecimal digits from `hex` and write the
   * values to `binary` as `len` bytes. Return 0 on success, or -1 if
   * the input does not consist of hex digits).
   */
  extern int hex_to_bytes(unsigned char *binary, const char *hex, size_t len);

The patch moves the comment verbatim. Words in backticks (`binary`, `hex`, `len`) are parameter names.

The function converts pairs of hexadecimal digits (base 16, ASCII encoded) to bytes (base 256). A byte can be seen as an array of bits; thus the output is also binary (base 2) without requiring further conversion.

Calling the variable "binary" may seem unspecific, but makes sense in the context of this function.

Does any of that help?

Thanks, René

Previous: Kevin DaudtNext: Kevin Daudt
Message 10 of 11 in “notes: move hex_to_bytes() to hex.c and export it”
  1. 1/3 notes: move hex_to_bytes() to hex.c and export itRené Scharfe, Oct 31, 2017
  2. 2/3 http-push: use hex_to_bytes()René Scharfe, Oct 31, 2017
  3. Jeff KingNov 1, 2017
  4. René ScharfeNov 1, 2017
  5. Jeff KingNov 1, 2017
  6. René ScharfeNov 4, 2017
  7. 3/3 sha1_file: use hex_to_bytes()René Scharfe, Oct 31, 2017
  8. Jeff KingNov 1, 2017
  9. Kevin DaudtNov 5, 2017
  10. René ScharfeNov 5, 2017
  11. Kevin DaudtNov 5, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.