Forum Discussion
Magnum_IP
Nimbostratus
Feb 26, 2014Binary 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
- Whoaa_aaa_14293
Nimbostratus
What language? - Magnum_IP
Nimbostratus
I'm hoping to do this in an iRule, so tcl - Magnum_IP
Nimbostratus
Can I use binary scan to get the job done? - Kevin_Stewart
Employee
Can you base64-encode an example and post it here? - Magnum_IP
Nimbostratus
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. - Kevin_Stewart
Employee
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
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects