1

Looking to solve the following code in order to come up with the name for the below array

 let name=[42,67,74,62,6A,1F,58,64,60,66,64,71];
 for(let i=0;i<name.length;i++)
 {
 name[i] =name[i]+1;
 }

Any suggestions what would be the output?

Thanks

3 Answers 3

1

Your initial array is not a valid array because 6A and 1F are not valid numbers in JavaScript. Furthermore, if all the numbers in the array are hexidecimal numbers, you would need to precede them with 0x for them to behave correctly (because the base10 number 42 is not the same as the base16 number 42). So lets get your array in order first:

let name = [0x42,0x67,0x74,0x62,0x6A,0x1F,0x58,0x64,0x60,0x66,0x64,0x71];

We could have also used strings and parsed them into base16 (hex) numbers:

let name = ['42','67','74','62','6A','1F','58','64','60','66','64','71'].map(n => parseInt(n, 16));

Now we can use String.fromCharCode to determine what the array says:

name.map(String.fromCharCode).join('')

Though I'm not sure what that says or means...

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

5 Comments

Thanks for the comment Can I know the output what would be the word?
Part of this site is showing you the door - you must walk through. Copy the code above into your browser console.
That doesn't help much. The code I provided works. The output doesn't make any sense, but that's what you gave me. I have no idea where these numbers come from, what they're supposed to mean, or if they're even supposed to be base16 to begin with (ex. 6A can represent numbers in base12, base20) - I have no idea.
@RyanWheale but 0x1F can not be represented in base 12
@Alex you're missing my point. Yes 1F is technically too high for base 12 (though it is parseable with radix 12, it just gets "rounded" down), but the point is these numbers could be in base 20, or base 26, base 32, or whatever - the OP didn't specify and just says "it doesn't work". They're not giving us anything to go on to help solve whatever problem they are having. I suppose ASCII is enough of a clue... but still. a bit of a guessing game on our part.
0

You want something this?

let name = [42,67,74,62,0x6A,0x1F,58,64,60,66,64,71];
var str = "";
 for(let i=0;i<name.length;i++)
 {
 str+=String.fromCharCode(name[i]);
 }
 
 console.log(str);

Or even:

let name = [42,67,74,62,0x6A,0x1F,58,64,60,66,64,71];
    console.log(String.fromCharCode(...name));

*NOTE your values are in hexadecimal base you should specify it by adding 0x

1 Comment

Is there a word that I come up with?
0

Because we don't know which base the numbers represent and the output for hex doesn't say anything we try bases from 2 - 30 and check if for some base the output is something valid.

Note: to remove all non printable ASCII characters we use the regexp

/[^ -~]+/g

Instead of using JavaScript here there are a lot of online decoder tools like https://geocaching.dennistreysa.de/multisolver/ .There you can type in your input and press decode and it will decode in a lot of ways. This would be a more convenient way to get a word from a input than using JavaScript.

let name = ['42','67','74','62','6A','1F','58','64','60','66','64','71'];
const ob = {};
for(let i = 2; i <= 30; i++){
let temp = name.map(x => parseInt(x, i));
// Remove the non printable ASCII Characters 
let tempRes = String.fromCharCode(...temp).replace(/[^ -~]+/g, "");
ob[`Base${i}`] = tempRes;
}

console.log(ob);

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.