Forum Discussion

anupambit1797's avatar
anupambit1797
Iron Contributor
Oct 05, 2024
Solved

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 == 162),

I want to perform the above functions in this Column "F" which is the BIN of Column "E", but getting Errors in all functions, in PQ microsoft page, their example also I can't see.

 

Could you please educate me/Perform the above 5 functions in Column "F", using PQ,

 

Thanks in Advance,

Br,

Anupam

 

  • Hi anupambit1797 

     

    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:

    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)

  • Lorenzo's avatar
    Lorenzo
    Silver Contributor

    Hi anupambit1797 

     

    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:

    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)

    • Lorenzo 

      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.

      • Lorenzo's avatar
        Lorenzo
        Silver Contributor

        SergeiBaklan 

        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...

Resources