cancel
Showing results for
Search instead 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,
AddColumns(AddColumns(ForAll(
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,
AddColumns(AddColumns(ForAll(
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 ,

Thank for your reply

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.

I made a adjustment per you need. please try this:

``````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,
AddColumns(AddColumns(ForAll(
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!

## Helpful resources

Announcements

#### Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

#### Claim Your Badge & Digital Swag!

Check out how to claim yours today!

#### Are Your Ready?

Test your skills now with the Cloud Skill Challenge.

#### Demo Extravaganza is Back!

We are excited to announce that Demo Extravaganza for 2021 has started!

#### Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Top Solution Authors
Top Kudoed Authors
Users online (43,877)