Menu
What you (apparently!) want to do is convert a pair of bytes to a single byte, by interpreting the two bytes as ASCII symbols which in turn represent hex digits, and emitting the corresponding hexadecimal value.
Active1 month ago
Hex Conversion
I want to convert two ASCII bytes to one hexadecimal byte.eg.
Pokemon black 2 gba download zip. Download ROM Pokemon - Black Version (DSi Enhanced)(USA) - Category: Nintendo DS. Pokemon - Black Version (DSi Enhanced)(USA). Black Version (DSi Enhanced)(USA) (EU).zip File size 106.01 Mo Category Nintendo DS Language. Genre Platform Developer Nintendo Year 20xx Player(s) 1 Controller Controller Media Cartridge Online since. Jan 17, 2019 Pokemon Black is one of the most downloaded and played Fifth Generation Pokemon Game having lots of technological updates and features. The Pokemon Black Version NDS Download is developed by the Game Freak and Published by the two leading companies name as Nintendo and The Pokemon Company. Gameplay and Full Walkthrough of the game is shared below having lot’s changes. Download 5585 - Pokemon - Black Version ROM for Nintendo DS(NDS) and Play 5585 - Pokemon - Black Version Video Game on your PC, Mac, Android or iOS device! In the Pokemon - Black Version the pokemon player starts with one Pokemon and starts the search for another Pokemon who can catch with the Pokeball. After catching several pokemon you can train them and fight with them to win badges and your Pokemon to grow and become more strong. Pokemon Black redefines the original formula we all fell in love with when we first played Red & Blue as kids. As a Rpg, Pokemon is amazingly balanced and is accessible to all types of audiences. The sounds are just as good as you would expect from a pokemon game, and the new sprites and 3D enviroments are beautiful to look at.
0x30 0x43 => 0x0C , 0x34 0x46 => 0x4F
..The ASCII bytes are a number between
0
and 9
or a letter between A
and F
(upper case only), so between 0x30
.. 0x39
and 0x41
.. 0x46
I know how 'to construct'
0x4F
with the numbers 0x34
and 0x46 : 0x4F = 0x34 * 0x10 + 0x46
So, in fact, i would to convert one ASCII byte in hexadecimal value.
For that, i can build and array to assign the hexadecimal value to the ASCII char :
But, maybe it have a most « proper » solution.
The program will be run on an AVR µC and is compiled with
avr-gcc
, so scanf()
/ printf()
solutions aren't suitable.Have you got an idea ?Thanks
ojblass12.3k2020 gold badges7070 silver badges118118 bronze badges
Loïc G.Loïc G.2,03422 gold badges1616 silver badges2929 bronze badges
5 Answers
i can't make sense of your examples, but if you want to convert a string containing hexadecimal ascii characters to its byte value (e.g. so the string '56' becomes the byte 0x56, you can use this (which assumes your system is using ASCII)
You'd use it like e.g.
And res (which must be at least half the length of the
in
parameter) now contains the 2 bytes 0x12,0x34Note also that this code needs the hexadecimal letters A-F to be capital, a-f won't do (and it doesn't do any error checking - so you'll have to pass it valid stuff).
nosnos182k4545 gold badges335335 silver badges439439 bronze badges
You can use
Carl NorumCarl Norumstrtol()
, which is part of avr-libc, or you can write just your specific case pretty easily:182k2222 gold badges359359 silver badges434434 bronze badges
The task:
Convert a string containing hexadecimal ascii characters to its byte valuesso ascii
'FF'
becomes 0xFF
and ascii '10' (x31x30x00)
becomes 0x10
// the final result should be:
//1. Firt step: convert asciiString so it contains upper cases only:
use:
//2. Convert a string containing hexadecimal ascii characters to its byte values:
//3. print result:
// use:
//4. The result should be:
0xAA 0xAA 0x12 0xFF
//5. This is the test program:
Ascii To Hex Conversion Program In Embedded C
sg7sg74,43811 gold badge2525 silver badges3737 bronze badges
Opal57.9k2121 gold badges120120 silver badges138138 bronze badges
DmitryDmitry
Here's a version that works with both upper and lower-case hex strings:
Loïc G.2,03422 gold badges1616 silver badges2929 bronze badges
Pillar of CreationPillar of Creation
Not the answer you're looking for? Browse other questions tagged casciihexavr-gcc or ask your own question.
Active2 years, 10 months ago
i have an hex string and want it to be converted to ascii string in C. How can i accomplish this??
nikhilnikhil3,0061818 gold badges4949 silver badges7878 bronze badges
3 Answers
you need to take 2 (hex) chars at the same time.. then calculate the int value and after that make the char conversion like..
char d = (char)intValue;
do this for every 2chars in the hex string
this works if the string chars are only 0-9A-F:
sharpnersharpner2,75833 gold badges1313 silver badges2525 bronze badges
strtol()
is your friend here. The third parameter is the numerical base that you are converting.Example:
Nisse Engström4,24999 gold badges2222 silver badges3737 bronze badges
BaldrickkBaldrickk2,85911 gold badge77 silver badges2323 bronze badges
Few characters like alphabets i-o couldn't be converted into respective ASCII chars .like in string '6631653064316f30723161' corresponds to fedora . but it gives fedra
Just modify hex_to_int() function a little and it will work for all characters.modified function is
Now try it will work for all characters.
MD XF4,43455 gold badges3131 silver badges5757 bronze badges
summarysummary
protected by revoApr 13 '18 at 20:19
Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?
Would you like to answer one of these unanswered questions instead?