Differences between revisions 34 and 35
Revision 34 as of 2017-06-01 16:50:15
Size: 1413
Editor: KaiJaeger
Comment:
Revision 35 as of 2017-06-01 17:15:55
Size: 1385
Editor: KaiJaeger
Comment:
Deletions are marked like this. Additions are marked like this.
Line 11: Line 11:
must be 32 bits signed integer
Run[61] r←1 hex ##.THIS⍎r⊣⎕PP←34
       ∧
* Command Execution Failed: must be 32 bits signed integer

User Commands Int2Hex and Hex2Int

Overview

Although Dyalog comes from two built-in user commands for converting a hex number into an integer and vice versa (]ToHex and ]FromHex), fromHex is too limited to be really useful.

For example, is one wishes to convert an error code returned by the Windows Task Scheduler:

      ]tohex 2147942667                              
* Command Execution Failed: must be 32 bits signed integer

With the excellent function Hex written and contributed by PhilLast - which is the internal engine of the two user commands - this can be avoided:

      ]Int2hex 2147942667                              
8007010b
      ]Hex2Int 8007010b
2147942667

This is Phil's underlying code:

      Hex←{
          ⎕IO←0 ⋄ ⎕ML←1
          t←0∊⊃⍬⍴0⍴⊂⍵
          a←⎕D,'abcdef',⎕D,6⍴⎕A
          t:a⌷⍨⊂⍉16⊥⍣¯1⊢⍵
          16⊥⍉16|a⍳⍵
    ⍝ ⍵ dec-number or hex-string
    ⍝ ← hex-string or dec-number
    ⍝   accepts hex as CAPS or small
    ⍝   returns hex as small
    ⍝   dec to hex is rank increasing
    ⍝   hex to dec is rank decreasing
      }

Download

Download the script.

Authors: Logic=PhilLast, user command=KaiJaeger


CategoryDyalogUserCommands

UserCommands/Hex (last edited 2019-05-30 07:48:57 by KaiJaeger)