cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
RioArifin
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
v-siky-msft
Community Support
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:

Snipaste_2020-11-13_16-24-33.png

Hope this helps.

Sik

View solution in original post

5 REPLIES 5
v-siky-msft
Community Support
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:

Snipaste_2020-11-13_16-24-33.png

Hope this helps.

Sik

View solution in original post

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. 

 

RioArfn
Frequent Visitor

Here's the screen I created:

 

2020-11-18 09_53_01.png

 

 

v-siky-msft
Community Support
Community Support

Hi @RioArfn @RioArifin ,

 

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.

Snipaste_2020-11-20_11-25-29.png

Hope this helps.

Sik

 

Thanks, it works!

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

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

MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

secondImage

Are Your Ready?

Test your skills now with the Cloud Skill Challenge.

Top Solution Authors
Top Kudoed Authors
Users online (53,227)