on ‎2013 Mar 12 11:49 PM
Hi all,
I need to convert a HEX to string for X509 certificate serial number. Anyone have a simple function for this.
Right now I'm using MS SQL Server to do the conversion but would love to do it client side.
SELECT CONVERT(VARCHAR(MAX), CONVERT(VARBINARY(MAX), '0x3030303031303030303030323031303633393638', 1))
I'm using PB 12.5.1
Regards,
Adrian
Request clarification before answering.
When dealing with some certificate data I've used an of_hextobyte method to convert hex data to a byte. You could adapt that. Just call in it a loop stepping through your string two characters at a time. Think I may have borrowed this from PFC, but not sure.
char lch_char[]
integer li_byte
int li_dec[48 to 70], li_i, li_len
//Get the decimal code for hexadecimal value of '0' to 'F'
// Whose ASC Value are from 48 to 57 and 65 to 70
For li_i = 48 To 57
li_dec[li_i] = li_i - 48
Next
For li_i = 65 To 70
li_dec[li_i] = li_i - 55
Next
as_hex = upper(as_hex)
lch_char = as_hex
li_len = len (as_hex)
//Convert Hexadecimal data into decimal
For li_i = 1 to li_len
//Make sure only 0's through f's are present
Choose Case lch_char[li_i]
Case '0' to '9', 'A' to 'F'
li_byte = li_byte * 16 + li_dec[asc(lch_char[li_i])]
Case Else
Return li_byte
End Choose
Next
Return li_byte
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I'm sorry, Adrian, I'm not clear what data type variable you have that in, in PB. One would need that information to offer an answer.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Dan,
I'm sorry. I'm calling an API that is returning a string with a HEX value. I need to convert that string with the HEX value to regular ascii string.
As I mention my first post I'm using a varchar on SQL Server to convert the varchar by only putting in front 0x so that SQL Server takes it as a HEX value.
If I use the following syntax PB will give me an error.
ls_hex = "~h"+ls_string
Regards,
Adrian
OK, Adrian, I'm still confused I'm afraid. A hex string is a string, and it is certainly ASCII. So what do you really mean? Do you mean convert a hex number (of how many digits?) to a long (perhaps very long?) integer, and then represent that as a string?
Perhaps you could give a simple specific example of what should be converted to what.
If others are clearer on this than I am, do jump in.
| User | Count |
|---|---|
| 15 | |
| 9 | |
| 6 | |
| 5 | |
| 4 | |
| 4 | |
| 3 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.