0

I'm trying to convert a text string AAIA to binary. This is how Salesforce manages dependent picklists.

I essentially need to go from ascii to base64 to binary, but I think the binary needs to be bytes, not text.

Expected result is AAIA => 00000000 00000010 00000000, which means 15th item in my other list controls this one. I can't figure out how to make this work in Node! Using the above mentioned values on this site works, but no luck in Node.

1 Answer 1

1
  • You want to convert a string to binary.
  • You want to convert a string value of AAIA to 00000000 00000010 00000000.
  • You want to achieve this using Node.js.

If my understanding is correct, how about this answer?

Sample script:

In this sample, there are the outputs of 3 patterns.

const str = "AAIA";

// Pattern 1
const buf = Buffer.from(str, 'base64');
console.log(buf); // <--- <Buffer 00 02 00>

// Pattern 2
const byteAr = Uint8Array.from(buf);
console.log(byteAr); // <--- Uint8Array [ 0, 2, 0 ]

// Pattern 3
const result = buf.reduce((s, e) => {
    const temp = e.toString(2);
    return s += "00000000".substring(temp.length) + temp + " ";
}, "");
console.log(result); // <--- 00000000 00000010 00000000

References:

If I misunderstood your question and these were not the results you want, I apologize.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you @Tanaike! Pattern 3 is exactly what I'm after!
@McB Thank you for replying. I'm glad your issue was resolved. Thank you, too.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.