help needed regarding conversion of hex to binary

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

help needed regarding conversion of hex to binary

CdAB63
Is there a (easy and ready) way to convert hexa to binary. I mean,
convert data that was transformed

     x := myData asByteArray hex.

back to binary?


Reply | Threaded
Open this post in threaded view
|

Re: help needed regarding conversion of hex to binary

Ben Coman


On Tue, Sep 12, 2017 at 2:55 AM, Casimiro de Almeida Barreto <[hidden email]> wrote:
Is there a (easy and ready) way to convert hexa to binary. I mean, convert data that was transformed

    x := myData asByteArray hex.

back to binary?



I thought I'd try what usually works...  World > Tools > Finder > Examples
First to test what we know...    
      #(9 10 11 12) asByteArray  .  '090a0b0c' 
results in  #hex

but the reverse...
      '090a0b0c' .  #(9 10 11 12) asByteArray  .  
doesn't show any result, 
so perhaps there is no easy way.

But this might give you a starting point...
   hexString := #(9 10 11 12) asByteArray hex.
   (NumberParser on: '16r', hexString) nextInteger asByteArray " ==>  #[9 10 11 12]"

cheers -ben
Reply | Threaded
Open this post in threaded view
|

Re: help needed regarding conversion of hex to binary

Sven Van Caekenberghe-2
ByteArray readHexFrom: #[ 0 1 2 3 4 5 6 7 8 9 10 ] hex.

> On 12 Sep 2017, at 14:47, Ben Coman <[hidden email]> wrote:
>
>
>
> On Tue, Sep 12, 2017 at 2:55 AM, Casimiro de Almeida Barreto <[hidden email]> wrote:
> Is there a (easy and ready) way to convert hexa to binary. I mean, convert data that was transformed
>
>     x := myData asByteArray hex.
>
> back to binary?
>
>
>
> I thought I'd try what usually works...  World > Tools > Finder > Examples
> First to test what we know...    
>       #(9 10 11 12) asByteArray  .  '090a0b0c'
> results in  #hex
>
> but the reverse...
>       '090a0b0c' .  #(9 10 11 12) asByteArray  .  
> doesn't show any result,
> so perhaps there is no easy way.
>
> But this might give you a starting point...
>    hexString := #(9 10 11 12) asByteArray hex.
>    (NumberParser on: '16r', hexString) nextInteger asByteArray " ==>  #[9 10 11 12]"
>
> cheers -ben