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()
Solved! Go to Solution.
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
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
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.
Here's the screen I created:
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.
Hope this helps.
Sik
Thanks, it works!
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
This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.
Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.
User | Count |
---|---|
194 | |
67 | |
46 | |
41 | |
28 |
User | Count |
---|---|
253 | |
119 | |
86 | |
84 | |
83 |