> On Dec 3, 2014, at 9:36 PM, P THE AWESOME <[email protected]> wrote: > > I am trying to convert a string with the byte number in it into a real byte. > > var string = "23"; // Or it could be 4E, CA, 22, FF, or any other byte > var byte = somehowConvertStringToByte(string); // The variable "byte" Should > look like 0x23 to NodeJS > var otherByte = 0x23; // This is 100% equal to the variable "byte." NodeJS > will see this variable and "byte" the exact same way. > > Hopefully this makes sense. I'm have to generate some stupid checksums to get > my UPB serial PIM to accept commands. I have the reset of the code working. > I'm making a CLI script that generates UPB commands and then sends them with > node-serialport.
Try this:
parseInt(string.slice(0,2), 16)
string.slice(0, 2) grabs the first two characters: two nybbles, one byte.
parseInt(str, 16) parses that into a native Number, assuming base 16
(hexadecimal, like your example)
0x23 is a literal for a Number, so that, too, makes a value that is equal to
what that returns.
Aria
--
Job board: http://jobs.nodejs.org/
New group rules:
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
---
You received this message because you are subscribed to the Google Groups
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/nodejs/8E4B1E42-07D1-4AE9-8468-5C33B7ADC4F0%40nbtsc.org.
For more options, visit https://groups.google.com/d/optout.
smime.p7s
Description: S/MIME cryptographic signature
