cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
RioArifin
Frequent 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

6 REPLIES 6
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

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!

Anonymous
Not applicable

Hi @v-siky-msft 

I am trying to use your formula but I just need to convert from Hex to Decimal, no need for ASCII.

I use RFID reader on PowerApps and when I scan the card it populates the field like ;0468DFD?

I remove the semicolon and used online converters which gives me 73981904 decimal number as a result.

I tried to modify formula by converting from

If(DecFL=0 && DeciSL=0,"",Char(DecFL*16+DeciSL))

to

If(DecFL=0 && DeciSL=0,"",DecFL*16+DeciSL)

 but no luck.

it gives me some different number.

I am sure I am missing some points.

Do you have any idea where is the missing point please?

Thanks

Helpful resources

Announcements
Power Apps Africa Challenge 2022

Power Apps Africa Challenge

Your chance to join an engaging competition of Power Platform enthusiasts.

Super User 2 - 2022 Congratulations

Welcome Super Users

The Super User program for 2022 - Season 2 has kicked off!

September Events 2022

Check out all of these events

Attend in person or online, there are incredible conferences and events happening all throughout the month of September.

Government Carousel

New forum: GCC, GCCH, DoD - Federal App Makers (FAM)

In response to the unique and evolving requirements of the United States public sector, Microsoft has created Power Apps US Government.

Users online (5,149)