Having a problem here. I recieve data from hardware as HEX numbers. I use this to make them into strings(it is intended):
arr.push(data.charCodeAt(0).toString(16))
It works well. For example I recieve 0x00 and this code correctly adds a '0' string to the array.
But there is a problem. JS automatically understands these codes as symbols. And when I try 0xAA or 0x80 I recieve FFFD. As I understand. it means that there is no such symbol in utf-8.
How do I make js understand my data as hex-numbers, but not as symbol codes?
Edit: I figured out that my problem was in my wrong way of using the library which recieved data from hardware.
Just convert the Hex number to decimal
yourNumber = parseInt(hexString, 16);
To convert hexadecimal to decimal you can use the next function:
parseInt(hexValue, 16)
Hope this helps :)
data = '0XAA'
data1 = '0X80'
console.log( parseInt(data, 16))
console.log( parseInt(data1, 16))
Okay, I figured out that my problem was in a library I used to recieve data
Related
So, I am trying to turn a number to binary, which seems fine in both javascript and python, but my issue is that when I do so, they both return a different binary string.
I enter: 585190997647163394
JavaScript returns: 100000011111000001000001110010100100100001000000000000000000
Python returns: 100000011111000001000001110010100100100001000000000000000010
If you canΒ΄t see the difference, the penultimate digit in the string python has returned is a 1 instead of a 0, like in the javascript string.
Please explain to me how this can happen/how to fix it.
Thank you!
Here is the code if needed:
js:
var bin = (+in).toString(2);
console.log(bin);
py:
print(bin(int(input("bingledingle >"))))
JavaScript uses floating point numbers with double precision. 585190997647163394 is too large.
585190997647163394 > Number.MAX_SAFE_INTEGER
The number is rounded to 585190997647163392.
You can use BigInt instead.
Python has numbers with arbitrary precision. Numbers are stored as strings. Python doesn't round the number to store it.
So im writing an exploit and im getting an address such as 0x00708001e9ab0b10 which is obviously a 64 bit hex address. The address I need is 0x1e9ab0b10 to my calculations this is the upper 28 bits but some told me this is 48 bits and up so i dont know but i basically need to remove 0x0070800 the first 7 numbers of the hex string/number and give me something like 0x00000001e9ab0b10 which i would prefer!!! or something like 0x1e9ab0b10 mind you as well i need this done in JavaScript which is what my exploit is for
Not sure I properly understand what you want, but if that hex is a string, you can call String.prototype.slice(x) on it which returns a copy of the string with the first x characters removed.
truncate = (hexString) => '0x0000000' + hexString.slice(9);
truncate('0x00708001e9ab0b10');
If the actual number isn't of any consequence then convert it into a string and slice it.
console.log('0x'+0x00708001e9ab0b10.toString(16).slice(5))
I really want to work with hex values in TTN but I haven't found a way to get the 'frm_payload'. So now I use a default script to convert it to decimals but I can't find a solution for turning it back into a hex value. I think the solution is probably quite simple but I keep overlooking it, so maybe someone can help me and give a push in the right direction.
This is my code, it reads the payload and turns the first hex value (7C) to a decimal number (124):
var decoded = {};
function Decoder(bytes, port) {
if (port == 1) {
decoded.test = bytes[0];
}
return decoded;
}
And this is the output I get:
{
"test": 124
}
Convert a number to a hexadecimal string with:
hexString = yourNumber.toString(16);
And reverse the process with:
yourNumber = parseInt(hexString, 16);
the problem i'm facing is when i inputting emoji from an android device to display on a browser, the emoji is converted its form of Decimal code like π π π. is there any way to detect the decimal code then convert it to Hex or Unicode with javascript? because with Hashtag in front of the number, it might lead to confusion as hashtag input.
I've used the toString() method but it doesn't seem to solve the problem
decimalNumber.toString( radix )
maybe use \u---- where ---- is hexacode ( in utf8 string) ?
I'm looking for a two way encryption method that will output only numbers approx 9 char length.
somthing like skip32, but I cannot use skip32.
I need it to be available to php and javascript. Thank you.