Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
audiowmark
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Stefan Westerfeld
audiowmark
Commits
b582c712
Commit
b582c712
authored
Jan 04, 2019
by
Stefan Westerfeld
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add conversion utils: byte vector <-> hex string
Signed-off-by:
Stefan Westerfeld
<
stefan@space.twc.de
>
parent
7e8980f5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
0 deletions
+37
-0
utils.cc
src/utils.cc
+34
-0
utils.hh
src/utils.hh
+3
-0
No files found.
src/utils.cc
View file @
b582c712
...
...
@@ -55,3 +55,37 @@ bit_vec_to_str (const vector<int>& bit_vec)
return
bit_str
;
}
vector
<
unsigned
char
>
hex_str_to_vec
(
const
string
&
str
)
{
vector
<
unsigned
char
>
result
;
if
((
str
.
size
()
%
2
)
!=
0
)
// even length
return
vector
<
unsigned
char
>
();
for
(
size_t
i
=
0
;
i
<
str
.
size
()
/
2
;
i
++
)
{
unsigned
char
h
=
from_hex_nibble
(
str
[
i
*
2
]);
unsigned
char
l
=
from_hex_nibble
(
str
[
i
*
2
+
1
]);
if
(
h
>=
16
||
l
>=
16
)
return
vector
<
unsigned
char
>
();
result
.
push_back
((
h
<<
4
)
+
l
);
}
return
result
;
}
string
vec_to_hex_str
(
const
vector
<
unsigned
char
>&
vec
)
{
string
s
;
for
(
auto
byte
:
vec
)
{
char
buffer
[
256
];
sprintf
(
buffer
,
"%02x"
,
byte
);
s
+=
buffer
;
}
return
s
;
}
src/utils.hh
View file @
b582c712
...
...
@@ -7,4 +7,7 @@
std
::
vector
<
int
>
bit_str_to_vec
(
const
std
::
string
&
bits
);
std
::
string
bit_vec_to_str
(
const
std
::
vector
<
int
>&
bit_vec
);
std
::
vector
<
unsigned
char
>
hex_str_to_vec
(
const
std
::
string
&
str
);
std
::
string
vec_to_hex_str
(
const
std
::
vector
<
unsigned
char
>&
vec
);
#endif
/* AUDIOWMARK_UTILS_HH */
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment