LMMP 4.3.0
Lamina High-Precision Arithmetic Library
载入中...
搜索中...
未找到
from_hex.c 文件参考
#include "impl/str_conv.h"
#include "mparam.h"
#include "lmmp/lmmpn.h"
from_hex.c 的引用(Include)关系图:

浏览该文件的源代码.

函数

mp_size_t lmmp_from_hex_ (mp_ptr dst, const char *src, mp_size_t len)
 十六进制字符串转limb数组 [src,len,16] to [dst,return value,B]

变量

static const mp_byte_t lmmp_hex_val_tab [256]
 Copyright (C) 2026 HJimmyK (Jericho Knox)

函数说明

◆ lmmp_from_hex_()

mp_size_t lmmp_from_hex_ ( mp_ptr dst,
const char * src,
mp_size_t len )

十六进制字符串转limb数组 [src,len,16] to [dst,return value,B]

参数
dst结果输出指针
src字符串源指针
len字符串长度
警告
len>=0, dst!=NULL, src!=NULL, src[i] in {'0'-'9','a'-'f','A'-'F'}
注解
低位digit(nibble)在数组前端;将忽略末尾的'0';将会忽略大小写,'a'等同于'A'
返回
转换后的结果的 limb 长度(零值返回0)

在文件 from_hex.c 第 35 行定义.

35 {
36 lmmp_param_assert(dst != NULL && src != NULL);
37 do {
38 if (len == 0)
39 return 0;
40 } while (src[--len] == '0');
41 ++len;
42
43 mp_size_t nfull = len >> 4;
44 const char* sp = src;
45 for (mp_size_t i = 0; i < nfull; ++i, sp += 16) {
46 mp_limb_t l = 0;
47 // 组内自高向低读,使得 sp[j] 落在第 j 个 nibble
48 for (int j = 15; j >= 0; --j)
49 l = (l << 4) | lmmp_hex_val_tab[(mp_byte_t)sp[j]];
50 dst[i] = l;
51 }
52
53 int r = (int)(len & 15);
54 if (r) {
55 mp_limb_t l = 0;
56 for (int j = r - 1; j >= 0; --j)
57 l = (l << 4) | lmmp_hex_val_tab[(mp_byte_t)sp[j]];
58 dst[nfull] = l;
59 }
60
61 return nfull + (r != 0);
62}
static const mp_byte_t lmmp_hex_val_tab[256]
Copyright (C) 2026 HJimmyK (Jericho Knox)
uint8_t mp_byte_t
定义 lmmp.h:91
uint64_t mp_size_t
定义 lmmp.h:93
uint64_t mp_limb_t
定义 lmmp.h:92
#define lmmp_param_assert(x)
定义 lmmp.h:509

引用了 lmmp_from_hex_(), lmmp_hex_val_tab , 以及 lmmp_param_assert.

被这些函数引用 check_hex_one(), lmmp_from_hex_() , 以及 TEST_CASE().

函数调用图:
这是这个函数的调用关系图:

变量说明

◆ lmmp_hex_val_tab

const mp_byte_t lmmp_hex_val_tab[256]
static
初始值:
= {
['0'] = 0, ['1'] = 1, ['2'] = 2, ['3'] = 3, ['4'] = 4,
['5'] = 5, ['6'] = 6, ['7'] = 7, ['8'] = 8, ['9'] = 9,
['A'] = 10, ['B'] = 11, ['C'] = 12, ['D'] = 13, ['E'] = 14, ['F'] = 15,
['a'] = 10, ['b'] = 11, ['c'] = 12, ['d'] = 13, ['e'] = 14, ['f'] = 15,
}

Copyright (C) 2026 HJimmyK (Jericho Knox)

This file is part of LMMP.

LMMP is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this library. If not, see https://www.gnu.org/licenses/.

SPDX-License-Identifier: LGPL-3.0-or-later

在文件 from_hex.c 第 28 行定义.

被这些函数引用 lmmp_from_hex_().