0

How can I do bitwise operation between string and hexadecimal?
I need to use input of string to bitwise OR with hexadecimal and result should be hexadecimal.

First, input is string of time.
So 23:00 would be ["23", "00"].
Then I need it in hexadecimal as it is. For example, 23->0x23, 11->-0x11.
Now, bitwise OR with hexadecimal. But it doesn't give the result I want.
Expected result of (time[0] | 0x80) is 0xA3, where time[0] is 0x23 (0x isn't necessary)
Below is what I coded.

let input = "23:00"
let time = input.split(":"); //--> ["23","00"]
console.log(time[0] | 80); //--> 87
console.log(time[0] | "80"); //--> 87
console.log("0x"+time[0] | 80); //--> 115
console.log("0x"+time[0] | "0x80") //--> 163

1 Answer 1

2

you need to use proper radix in string2int2string conversions:

let input = "23:00"
let time = input.split(":"); //--> ["23","00"]
let temp = parseInt(time[0],16) | 0x80;
console.log(temp.toString(10)); // prints 163
console.log(temp.toString(16)); // prints a3

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

Comments

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.