little endian

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • CTG

    little endian


    var x = "B113769A"

    How do you convert B113769A to "9A7613B1" to get the proper
    conversion ?
  • Evertjan.

    #2
    Re: little endian

    RobG wrote on 22 mei 2008 in comp.lang.javas cript:
    On May 22, 11:09 am, CTG <BadMul...@gmai l.comwrote:
    >var x = "B113769A"
    // Return if has invalid characters
    if (/[^a-f0-9]/.test(x.toLower Case())) return;
    if ( /[^a-f0-9]/i.test(x) ) return;
    // Might need left padding
    x = (x.length % 2)? '0'+x : x;
    >
    // Split into an array of pairs, reverse and join again
    return x.match(/../g).reverse().jo in('');
    Nice! Will remember that one.


    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)

    Comment

    • RobG

      #3
      Re: little endian

      On May 22, 5:09 pm, "Evertjan." <exjxw.hannivo. ..@interxnl.net wrote:
      RobG wrote on 22 mei 2008 in comp.lang.javas cript:
      >
      On May 22, 11:09 am, CTG <BadMul...@gmai l.comwrote:
      var x = "B113769A"
        // Return if has invalid characters
        if (/[^a-f0-9]/.test(x.toLower Case())) return;
      >
      if ( /[^a-f0-9]/i.test(x) ) return;
      Ah yes...
      >
        // Might need left padding
        x = (x.length % 2)? '0'+x : x;
      >
        // Split into an array of pairs, reverse and join again
        return x.match(/../g).reverse().jo in('');
      >
      Nice! Will remember that one.
      Credit where credit's due - the inspiration came from the second
      banana example here:

      <URL: http://www.merlyn.demon.co.uk/js-valid.htm#JS >


      --
      Rob

      Comment

      Working...