Forum Discussion

Magnum_IP's avatar
Magnum_IP
Icon for Nimbostratus rankNimbostratus
Feb 26, 2014

Binary to decimal

I'm unfortunately stuck and need some help.

 

I have a variable with a binary value in it. I need to split the value in two; the first 64 bits and the remainder and store these in two new variables. I also need to convert the 64 bits into an 8 digit decimal value.

 

Any assistance greatly appreciated.

 

6 Replies

  • Kevin - here you go... nVkVI5xxeXvvzbGfFmarAfaDMTRTPnRlKVedR5oqcRGNaZFV8X3HfJ8RCLhIzdM5 My initial requirement is to decode this and store the first 64 bits in one variable and the remainder in another.
  • I'm not sure what you're expecting the decimal value to be, but here is perhaps one way to do this:

    set data "nVkVI5xxeXvvzbGfFmarAfaDMTRTPnRlKVedR5oqcRGNaZFV8X3HfJ8RCLhIzdM5"
    
    binary scan [b64decode $data] H* hdata
    log local0. $hdata
    
    set first [string range $hdata 0 15]
    set last [string range $hdata 16 end]
    
    log local0. $first
    
    set dec [expr 0x$first]
    log local0. $dec