Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Hexadecimal to String Conversion

Status
Not open for further replies.

yviswanathbe

Full Member level 4
Joined
Jun 14, 2007
Messages
221
Helped
10
Reputation
20
Reaction score
6
Trophy points
1,298
Activity points
3,066
Hi,

I am interfacing USB Flash drive to my micro controller using VINCULUM device via UART.

The Vinculum device sends the response in string format, but in micro controller i am receiving in hex format. i am storing all these hex values in an array.

for example if i send IDD command (IDD is for knowing the Device Information), the device will sends the following response

USB VID = $0930<CR>
USB PID = $6545<CR>
Vendor Id = Kingston<CR>
Product Id = DataTraveler 108<CR>
Revision Level = PMAP<CR>
I/F = SCSI<CR>
FAT32<CR>
Bytes/Sector = $0200<CR>
Bytes/Cluster = $004000<CR>
Capacity = $E98FC000 Bytes<CR>
Free Space = $ Bytes<CR>
<CR>
D:\><CR>

all these information i am receiving as a hex stream. What i want to do is, convert this information into string,dump to a file and store the file in the USB Flash Drive.

can somebody help how can i convert the hexadecimal number to string format in C.

Thanks and Regards,
Viswanath.
 

The hexadecimal data is already in a string format. What are you exactly asking for?
 

Hi,

Thanks for the reply.
Vinculum device response when IDD command is queried:
Code:
[CODE]USB VID = $0930<CR>
USB PID = $6545<CR>
Vendor Id = Kingston<CR>
Product Id = DataTraveler 108<CR>
Revision Level = PMAP<CR>
I/F = SCSI<CR>
FAT32<CR>
Bytes/Sector = $0200<CR>
Bytes/Cluster = $004000<CR>
Capacity = $E98FC000 Bytes<CR>
Free Space = $ Bytes<CR>
<CR>
D:\><CR>
[/CODE]

The above response from the Vinculum device is receiving in the micro controller UART as follows:

Code:
0D 55 53 42 20 50 49 44 20 3D 20 24 36 35 34 35 0D 56 65 6E 64 6F 72 20 49 64 20 3D 20 4B 69 6E 67 73 74 6F 6E 0D 50 72 6F 64 75 63 74 20 49 64 20 3D 20 44 61 74 61 54 72 61 76 65 6C 65 72 20 31 30 38 0D 52 65 76 69 73 69 6F 6E 20 4C 65 76 65 6C 20 3D 20 50 4D 41 50 0D 49 2F 46 20 3D 20 53 43 53 49 0D 46 41 54 33 32 0D 42 79 74 65 73 2F 53 65 63 74 6F 72 20 3D 20 24 30 32 30 30 0D 42 79 74 65 73 2F 43 6C 75 73 74 65 72 20 3D 20 24 30 30 34 30 30 30 0D 43 61 70 61 63 69 74 79 20 3D 20 24 45 39 38 46 43 30 30 30 20 42 79 74 65 73 0D 46 72 65 65 20 53 70 61 63 65 20 3D 20 24 45 33 35 33 34 30 30 30 20 42 79 74 65 73 0D 0D 44 3A 5C 3E 0D 0D 55 53 42 20 56 49 44 20 3D 20 24 30 39 33 30 0D 55 53 42 20 50 49 44 20 3D 20 24 36 35 34 35 0D 56 65 6E 64 6F 72 20 49 64 20 3D 20 4B 69 6E 67 73 74 6F 6E 0D 50 72 6F 64 75 63 74 20 49 64 20 3D 20 44 61 74 61 54 72 61 76 65 6C 65 72 20 31 30 38 0D 52 65 76 69 73 69 6F 6E 20 4C 65 76 65 6C 20 3D 20 50 4D 41 50 0D 49 2F 46 20 3D 20 53 43 53 49 0D 46 41 54 33 32 0D 42 79 74 65 73 2F 53 65 63 74 6F 72 20 3D 20 24 30 32 30 30 0D 42 79 74 65 73 2F 43 6C 75 73 74 65 72 20 3D 20 24 30 30 34 30 30 30 0D 43 61 70 61 63 69 74 79 20 3D 20 24 45 39 38 46 43 30 30 30 20 42 79 74 65 73 0D 46 72 65 65 20 53 70 61 63 65 20 3D 20 24 45 33 35 33 34 30 30 30 20 42 79 74 65 73 0D 0D 44 3A 5C 3E 0D

i stored this hex file in an array.

i want to convert this hex data into the original string as it is. I need this conversion because, i need to compare the response and proceed to further steps.

Thanks and Regards,
Viswanath
 

It's essentially a multiple line ASCII string, not a hex file. I would personally prefer to decode it as it comes in, without a need to store the full string.

The problem is about using C string processing functions in an intelligent way.
 

If you're asking to compare hex with these array members then Just subtract all your array members with 0x30H, so they all will be in HEX now and then you can compare the response and proceed to further steps.

or if you are looking to convert it in string ! then you don't have to do anything as FvM says.
It is already in the form in which you want it.

The difference is you are sending characters of string & receiving ASCII value of it.
But it's not makes any difference.

As you mentioned that you want to compare the response and proceed to further steps, then you can compare it with your array members.
I mean you can compare 0x4E with 'N' as both are the same thing. No need to convert 0x4E in to 'N' to do this comparison.

Or if you really wanna do this then you need to make a database of ASCII Codes which can give you HEX value of each Character & through which you can convert each ASCII Code into the set of string.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top