cancel
Showing results for
Did you mean:
Regular Visitor

convert Hex to Ascii text

Hi,

I have a hex value like this = "7C4C454C4D45445A36303031363435303738377C000000000000000000000000000000000000000000000000000000000000000000000000000000000000". I want to convert it to text, so it will be: "|LELMEDZ60016450787|".

How to do it?

In excel we have HEX2DEC()

1 ACCEPTED SOLUTION

Accepted Solutions
Community Support

Hi @RioArifin ,

It's only supported in PowerApps to convert the decimal number to ASCII by Char() function, so the Hex must be converted to Decimal first.

Please try this code, DecimalNum field store the decimal number and ASCII field store all converted ASCII text.

``````ClearCollect(Hex2Dec,{Hex:"1",Dec:1},{Hex:"2",Dec:2},{Hex:"3",Dec:3},{Hex:"4",Dec:4},{Hex:"5",Dec:5},{Hex:"6",Dec:6},{Hex:"7",Dec:7},{Hex:"8",Dec:8},{Hex:"9",Dec:9},{Hex:"A",Dec:10},{Hex:"B",Dec:11},{Hex:"C",Dec:12},{Hex:"D",Dec:13},{Hex:"E",Dec:14},{Hex:"F",Dec:15}); // Conversion table from Hex to Decimal
ClearCollect(
colLetter,
Sequence(Len(TextInput1.Text) / 2,1,2),
{
HexFL: Mid(
TextInput1.Text,
Value,
1
),
HexSL: Mid(
TextInput1.Text,
Value + 1,
1
)
}
),"DecFL",LookUp(Hex2Dec,Hex= HexFL).Dec,"DeciSL",LookUp(Hex2Dec,Hex= HexSL).Dec),
"DecimalNum",DecFL*16+DeciSL,"ASCII",Char(DecFL*16+DeciSL))
); // convert Hex Value in TextInput1 to Decimal and AscII
``````

Then Use the following code the concatenate all ASCII letter together.

``Concat(colLetter,ASCII)``

Test outcome:

Hope this helps.

Sik

5 REPLIES 5
Community Support

Hi @RioArifin ,

It's only supported in PowerApps to convert the decimal number to ASCII by Char() function, so the Hex must be converted to Decimal first.

Please try this code, DecimalNum field store the decimal number and ASCII field store all converted ASCII text.

``````ClearCollect(Hex2Dec,{Hex:"1",Dec:1},{Hex:"2",Dec:2},{Hex:"3",Dec:3},{Hex:"4",Dec:4},{Hex:"5",Dec:5},{Hex:"6",Dec:6},{Hex:"7",Dec:7},{Hex:"8",Dec:8},{Hex:"9",Dec:9},{Hex:"A",Dec:10},{Hex:"B",Dec:11},{Hex:"C",Dec:12},{Hex:"D",Dec:13},{Hex:"E",Dec:14},{Hex:"F",Dec:15}); // Conversion table from Hex to Decimal
ClearCollect(
colLetter,
Sequence(Len(TextInput1.Text) / 2,1,2),
{
HexFL: Mid(
TextInput1.Text,
Value,
1
),
HexSL: Mid(
TextInput1.Text,
Value + 1,
1
)
}
),"DecFL",LookUp(Hex2Dec,Hex= HexFL).Dec,"DeciSL",LookUp(Hex2Dec,Hex= HexSL).Dec),
"DecimalNum",DecFL*16+DeciSL,"ASCII",Char(DecFL*16+DeciSL))
); // convert Hex Value in TextInput1 to Decimal and AscII
``````

Then Use the following code the concatenate all ASCII letter together.

``Concat(colLetter,ASCII)``

Test outcome:

Hope this helps.

Sik

Frequent Visitor

Hi @v-siky-msft ,

It works,

But I have a scenario like this:

These value come from scanning RFID Label, so it will be many text in 1 text input.

ex:
7C4C454C4D45445A36303031363435303738377C000000000000000000000000000000000000000000000000000000000000000000000000000000000000
7C4C454C4D45445A36303031363435303738377C000000000000000000000000000000000000000000000000000000000000000000000000000000000000
7C4C454C4D45445A36303031363435303738377C000000000000000000000000000000000000000000000000000000000000000000000000000000000000

If I convert it with your code, the system read the "enter" and it doesn't work again because we added 1 char.

After converted, I want to split there value to a collection, so if 1 read 3 label, I will have 3 records.

Frequent Visitor

Here's the screen I created:

Community Support

Sorry for the late response.

``````ClearCollect(Hex2Dec,{Hex:"0",Dec:0},{Hex:"1",Dec:1},{Hex:"2",Dec:2},{Hex:"3",Dec:3},{Hex:"4",Dec:4},{Hex:"5",Dec:5},{Hex:"6",Dec:6},{Hex:"7",Dec:7},{Hex:"8",Dec:8},{Hex:"9",Dec:9},{Hex:"A",Dec:10},{Hex:"B",Dec:11},{Hex:"C",Dec:12},{Hex:"D",Dec:13},{Hex:"E",Dec:14},{Hex:"F",Dec:15});ClearCollect(col1,Split(TextInput3.Text,Char(10)));

Clear(colLetter);Clear(colAsc);
ForAll(col1,Collect(
colLetter,
Sequence(Len(Result) / 2,1,2),
{
HexFL: Mid(
Result,
Value,
1
),
HexSL: Mid(
Result,
Value + 1,
1
)
}
),"DecFL",LookUp(Hex2Dec,Hex= HexFL).Dec,"DeciSL",LookUp(Hex2Dec,Hex= HexSL).Dec),
"DecimalNum",DecFL*16+DeciSL,"ASCII",If(DecFL=0 && DeciSL=0,"",Char(DecFL*16+DeciSL)))
);Collect(colAsc,Concat(colLetter,ASCII));RemoveIf(colLetter,true))
``````

The colAsc Collection is what you need.

Hope this helps.

Sik

Frequent Visitor

Thanks, it works!

Announcements