Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

290
Views
convert byte array to C-Style WORD, DWORD adn String in javascript

Having to deal with many file header format i.e. bmp, tiff, wav, mp3, etc... I developed a few basic routines to deal with them. I was wondering if there was a better way? Also they do not deal with signed nor float value.

  function Read2BytesToUWord   (ThisArray, Offset, UseLittleEndian){

    let ThisWord              = 0;

    if(UseLittleEndian){
      ThisWord               |= ThisArray[Offset + 1].charCodeAt() << 8;
      ThisWord               |= ThisArray[Offset + 0].charCodeAt();
    } else {
      ThisWord                = ThisArray[Offset + 0].charCodeAt();
      ThisWord               |= ThisArray[Offset + 1].charCodeAt() << 8;
    }
    return Number((ThisWord));
  }
  function Read4BytesToUDWord   (ThisArray, Offset, UseLittleEndian){

    let ThisDWord             = 0;

    if(UseLittleEndian){
      ThisDWord               = ThisArray[Offset + 3].charCodeAt() << 24;
      ThisDWord              |= ThisArray[Offset + 2].charCodeAt() << 16;
      ThisDWord              |= ThisArray[Offset + 1].charCodeAt() << 8;
      ThisDWord              |= ThisArray[Offset + 0].charCodeAt();
    } else {
      ThisDWord               = ThisArray[Offset + 3].charCodeAt();
      ThisDWord              |= ThisArray[Offset + 2].charCodeAt() << 8;
      ThisDWord              |= ThisArray[Offset + 1].charCodeAt() << 16;
      ThisDWord              |= ThisArray[Offset + 0].charCodeAt() << 24;
    }
    return Number((ThisDWord));
  }
  function ReadBytesToString    (ThisArray, Offset, ThisLen){
    let ThisStr  = "";
    for(let Indx = 0; Indx < ThisLen; Indx++){
      ThisStr   += (ThisArray[Offset + Indx]); 
    }
    return ThisStr;
  }
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!