How to access binary data in a string in javascript

I use a device driver that captures the input signal from the reader (RFID) and sends it to the keyboard buffer (keyboard wedge). Captured data can (and should) be transformed using a java script.

This javascript is processed in the driver context - unfortunately, javascript receives the captured "binary" data in a DATA variable of type string.

You can imagine what javascript does: it interprets the input as unicode and thus does not allow you to specify bytes bytes inside the string - it varies arbitrarily between 1 ... 4 bytes depending on the value.

I just need to convert the binary string to its readable string format: xf9268970 should read "f9268970". Whatever I try so far.

Thanks for any feedback!

+3
source share
2 answers

Firstly, disclaimer. I did not work with binary data and javascript, but maybe this could help.

Perhaps you could skip the line and use charAt to view each character. From what I understand, charAt returns an ASCII value (not Unicode). So, instead of 4 bytes you will get 2 bytes (?)

var character;
for (var i = 0; i < str.length; i++) {
    character = str.charAt(i);
}

Maybe this link will point you in the right direction: charAt link

+1
source

I think you should listen to individual keystrokes and write the values ​​in a variable instead of reading a text field.

0
source

All Articles