Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
RIOT
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cm-projects
RIOT
Commits
9f90f312
Commit
9f90f312
authored
6 years ago
by
Toon Stegen
Browse files
Options
Downloads
Patches
Plain Diff
sys/fmt: add function for converting hex byte
parent
861fbe9a
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
sys/fmt/fmt.c
+6
-1
6 additions, 1 deletion
sys/fmt/fmt.c
sys/include/fmt.h
+11
-0
11 additions, 0 deletions
sys/include/fmt.h
with
17 additions
and
1 deletion
sys/fmt/fmt.c
+
6
−
1
View file @
9f90f312
...
@@ -132,6 +132,11 @@ static uint8_t _hex_nib(uint8_t nib)
...
@@ -132,6 +132,11 @@ static uint8_t _hex_nib(uint8_t nib)
return
_byte_mod25
((
nib
&
0x1f
)
+
9
);
return
_byte_mod25
((
nib
&
0x1f
)
+
9
);
}
}
uint8_t
fmt_hex_byte
(
const
char
*
hex
)
{
return
(
_hex_nib
(
hex
[
0
])
<<
4
)
|
_hex_nib
(
hex
[
1
]);
}
size_t
fmt_hex_bytes
(
uint8_t
*
out
,
const
char
*
hex
)
size_t
fmt_hex_bytes
(
uint8_t
*
out
,
const
char
*
hex
)
{
{
size_t
len
=
fmt_strlen
(
hex
);
size_t
len
=
fmt_strlen
(
hex
);
...
@@ -143,7 +148,7 @@ size_t fmt_hex_bytes(uint8_t *out, const char *hex)
...
@@ -143,7 +148,7 @@ size_t fmt_hex_bytes(uint8_t *out, const char *hex)
size_t
final_len
=
len
>>
1
;
size_t
final_len
=
len
>>
1
;
for
(
size_t
i
=
0
,
j
=
0
;
j
<
final_len
;
i
+=
2
,
j
++
)
{
for
(
size_t
i
=
0
,
j
=
0
;
j
<
final_len
;
i
+=
2
,
j
++
)
{
out
[
j
]
=
(
_hex_
nib
(
hex
[
i
])
<<
4
)
|
_hex_nib
(
hex
[
i
+
1
]
);
out
[
j
]
=
fmt
_hex_
byte
(
hex
+
i
);
}
}
return
final_len
;
return
final_len
;
...
...
This diff is collapsed.
Click to expand it.
sys/include/fmt.h
+
11
−
0
View file @
9f90f312
...
@@ -91,6 +91,17 @@ size_t fmt_bytes_hex(char *out, const uint8_t *ptr, size_t n);
...
@@ -91,6 +91,17 @@ size_t fmt_bytes_hex(char *out, const uint8_t *ptr, size_t n);
*/
*/
size_t
fmt_bytes_hex_reverse
(
char
*
out
,
const
uint8_t
*
ptr
,
size_t
n
);
size_t
fmt_bytes_hex_reverse
(
char
*
out
,
const
uint8_t
*
ptr
,
size_t
n
);
/**
* @brief Converts a sequence of two hex characters to a byte
*
* The hex characters sequence must contain valid hexadecimal characters
* otherwise the result is undefined.
*
* @param[in] hex Pointer to input buffer
* @returns byte based on hex string
*/
uint8_t
fmt_hex_byte
(
const
char
*
hex
);
/**
/**
* @brief Converts a sequence of hex bytes to an array of bytes
* @brief Converts a sequence of hex bytes to an array of bytes
*
*
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment