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

194
Views
convert base64 to array buffer, could contain negative numbers

i have a base64 string which converted to an array buffer contains 2000 parameters of integers.

i use these functions to decode and encode the data

   const base64 = "AAABAAEAAwACAAAAAQACAAAAAAAUAAoAAAAAAAAAAAABAAAAAAABAIAMpAYsAQAAAACADNAHLAEAAAAAgAzQBywBAAAAAAAAAAAAAAAAAAAiCxQAMgAyAFgCMgAAAEYAaQAUAGQAZABkADIAAAAAAAAAAAAAAAAAAgADAAQABQAAAAAABgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAQABAAEAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAAMABAAFAAYAAAAAAAAAAAAIADIAMgABAMIBAADIAAIAAAAKAAAAAQAAAAIAkAKg9swMsAQEAAAAAAAgA8IBAAAAAAAAAAAAAGQAigIAAAAAAAAAAJACoPbMDLAEBACU"

export const base64ToUint16ArrayBuffer = function (base64) {
  let binary_string = window.atob(base64);
  let len = binary_string.length
  let bytes = new Uint8Array(len)
  for (let i = 0; i < len; i++) {
    bytes[i] = binary_string.charCodeAt(i)
  }
  let uint16Array = new Uint16Array(bytes.buffer)
  return uint16Array
}

export const encodeArrayToBase64 = function (arrayBuffer) {
  // Converting arrayBuffer (which is a Uint16Array) to Uint8Array
  let data_8 = new Uint8Array(arrayBuffer.buffer, arrayBuffer.byteOffset, arrayBuffer.byteLength)
  // Decode array buffer to base64 string
  let arrayToBase64String = btoa(String.fromCharCode.apply(null, new Uint8Array(data_8)))
  return arrayToBase64String
}

the problem that i'm facing is that the base64 could contain negative numbers. How can i convert the base64 to get also the correct values for the negative numbers?

Thank you

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!