Forum Discussion
anupambit1797
Oct 05, 2024Iron Contributor
BinaryFormat.Binary , BinaryFormat.Byte,BinaryFormat.ByteOrder,BinaryFormat.Group,BinaryFormat.Lengt
Dear Experts, Greetings, I have a data like below( Most interesting is the Column "E"-> rat0BitMap:- The max size of the Column "E" is 11 bits ( which is max numOfPRB ...
- Oct 06, 2024
All the functions you refer don't do what you think/expect. For Power Query a Binary is a data Type (cf. Data types in Power Query & Power Query M Primer (Part 9): Types - Logical, Null, Binary)
As an example, if you invoke function Folder.Contents:
= Folder.Contents("D:\abc\wxyz")
you get something like:
where each Binary in [Content] must be "decoded" with the appropriate function (Excel.Workbook for the first 2, Csv.Document/Lines.FromBinary for the 3rd). But, there isn't always - in PQ functions' shared library - one for all kind of Binaries. Remember a few years ago where there wasn't a Pdf.Tables function (for the 4th file)...
Back to the functions you mentioned I suggest read Binary functions overview
Dec2Bin & Bin2Dec with Power Query
In the attached workbook you'll find 2 custom functions (not mine) as there's currently no PQ shared function similar to the Excel ones:
- fxNumberBaseConversion (Initial by MarcelBeug; Revised by BA_Pete)
(I added a Comment in the function to explain the difference) - fxBinToDec (by Vijay_A_Verma)
and a TableResult query
- In the 'Source' sheet I highlighted a couple of things for your attention
- In the 'Result' sheet the [Excel_BinToDec_Error] highlights why PQ returns null values in [Excel_BinToDec] (= 120 errors)
(Didn't investigate why Excel BIN2DEC returns -386 for Base = 1001111110)
- fxNumberBaseConversion (Initial by MarcelBeug; Revised by BA_Pete)
Lorenzo
Oct 06, 2024Silver Contributor
All the functions you refer don't do what you think/expect. For Power Query a Binary is a data Type (cf. Data types in Power Query & Power Query M Primer (Part 9): Types - Logical, Null, Binary)
As an example, if you invoke function Folder.Contents:
= Folder.Contents("D:\abc\wxyz")
you get something like:
where each Binary in [Content] must be "decoded" with the appropriate function (Excel.Workbook for the first 2, Csv.Document/Lines.FromBinary for the 3rd). But, there isn't always - in PQ functions' shared library - one for all kind of Binaries. Remember a few years ago where there wasn't a Pdf.Tables function (for the 4th file)...
Back to the functions you mentioned I suggest read Binary functions overview
Dec2Bin & Bin2Dec with Power Query
In the attached workbook you'll find 2 custom functions (not mine) as there's currently no PQ shared function similar to the Excel ones:
- fxNumberBaseConversion (Initial by MarcelBeug; Revised by BA_Pete)
(I added a Comment in the function to explain the difference) - fxBinToDec (by Vijay_A_Verma)
and a TableResult query
- In the 'Source' sheet I highlighted a couple of things for your attention
- In the 'Result' sheet the [Excel_BinToDec_Error] highlights why PQ returns null values in [Excel_BinToDec] (= 120 errors)
(Didn't investigate why Excel BIN2DEC returns -386 for Base = 1001111110)
SergeiBaklan
Oct 06, 2024MVP
If we have 10 bits the first bit means sign. Thus 1001111110 is negative number. To receive the value we invert other bits (will be 0110000001) and add 1 to it, finally it'll be 0110000010 or 386 decimal. Taking the sign result is -386.
- LorenzoOct 07, 2024Silver Contributor
Agreed. Just highlighted the difference with PQ output in case anupambit1797 would want both functions to behave the same in which case Vijay's function will need a couple of adjustments...