I'm tackling the problem for a week. However, I couldn't find a solution. I feel I'm in a maze now.
The problem is that how to pen's coordinates in a vector-based drawing system by decoding hex input.
Thank you so much in advance.
Problem
Input Data: F0A040004000417F417FC04000400090400047684F5057384000804001C0 5F204000400001400140400040007E405B2C4000804000
This is my code
//Decode Value
penDecode = (hex) => {
let decodeResult
let hR = hex.slice(0, 2)
let lR = hex.slice(2)
let hByte = parseInt(hR, 16).toString(2).padStart(7, 0)
let lByte = parseInt(lR, 16).toString(2).padStart(7, 0)
let binary = hByte + lByte;
decodeResult = (parseInt(hByte + lByte, 2)) - 8192
return decodeResult
}
//Slice input
for (let i = 0, len; i < hex.length; i += len) {
len = hex[i] >= '8' ? 2 : 4;
let num = hex.slice(i, i + len)
command.push(num)
if (num.length === 2) {
switch (num) {
case 'C0':
opcode = num;
break;
default:
opcode = ''
};
else if (num.length === 4) {
//decode HEX to the value
num = penDecode(num)
switch (opcode) {
case 'C0':
if (mvCurrentArr.length <= 1) {
mvCurrentArr.push(num)
} else {
mvArray.push(mvCurrentArr)
mv += `(${mvCurrentArr[1]},${mvCurrentArr[0]})`
mvCurrentArr = []
mvCurrentArr.push(num)
output += mv
}
}
Expected output Output become same as the picture above MV (4000, 0) (4000, -8000) (-4000, -8000) (-4000, 0) (-500, 0);