Jump to content
Karaethon

Getting numeric value of data

Recommended Posts

I can't find the answer to this on Google because i don't even know what to ask as search keywords. 

I have a chunk of data, uploaded file data, and for each byte I need to get that byte of it and find the numeric value (0 - 255) of that byte.  I can't find anything about data or file manipulation with javascript, I think I'm asking big G the wrong way.

Share this post


Link to post
Share on other sites

Doesnt that work on string data? Or will it work with the full ascii values? Btw, this is not browser based, is android app.

Share this post


Link to post
Share on other sites

If it's Android then why are you looking for a Javascript answer? Did you mean to say Java, even though the two are completely different languages?

You have code that's reading the contents of the file, right? At some point you should (a) have a String and you can .codePointAt(index), or (b) have a char and you can cast to int.

Share this post


Link to post
Share on other sites

Yes android and yes javascript, using droidscript as my ide. Uses js as the language. Im having trouble with AIDE and java, im still learning the proper way hut also want to practice using js way. 

Share this post


Link to post
Share on other sites

Then yes, String.charCodeAt is for strings. But that's probably what you have to work with. So unless you can tell me more so I don't have to try to guess, that's my answer.

Share this post


Link to post
Share on other sites

Ok, I have an array, table by name, it contains the numbers 0 through 255 (inclusive)in a random order. I am looping through the file data one byte at a time and i need the table's index of the numeric value that byte is equal to. So I need a way to get the numeric value of a byte so I can find it in table using .indexOf 

Share this post


Link to post
Share on other sites

Ohhh, well then, in that case,

String.prototype.charCodeAt.

Share this post


Link to post
Share on other sites

ok.... I'm having an odd problem here...

This code fails at line 16 because pivotTable is undefined there (line 15 is test for content), but not at line 5. But passkey at line 14 is not a problem...

01 class PivotValueEncryption{
02 constructor(){
03 var pivotTable = [162,1,53,...,93,91,16];
04 var passKey = "";
05 alert(pivotTable);
06 }
07 set key(value){
08 this.passKey = value;
09 }
10 get key(){
11 return this.passKey;
12 }
13 Pivot(character){                                             

14 alert(this.passKey);                                         

15 alert(this.pivotTable);
16 var charValue = this.pivotTable.indexOf(character.charCodeAt(0));
17 for (var i = 0; i<this.passkey.length-1; i++){
18 var pivotValue = this.pivotTable.indexOf(this.passkey.charCodeAt(i));
19 charValue = charValue + (pivotValue - charValue);
20
21 }
22 return charValue
23 }
24 }
25 var pve = new PivotValueEncryption;
26 pve.key="test";
27 alert(pve.key);
28 alert(pve.Pivot("A"))

Edited by Karaethon
14 and. 15 were out of line

Share this post


Link to post
Share on other sites

Ok, i accidentally fixed it....

I changed

03 var pivotTable = [162,1,53,...,93,91,16];
04 var passKey = "";

to

03 this.pivotTable = [162,1,53,...,93,91,16];
04 this.passKey = "";

if anyone knows why this worked, I'd appreciate the explanation. 

Share this post


Link to post
Share on other sites

"var" variables are only available to the function. If you define them in the constructor then you can't use them in the Pivot method.

Writing "this.pivotTable=" will create a member variable on the object instance. It's the same thing as if you wrote that in PHP.

Share this post


Link to post
Share on other sites

Ahhhh. Okay. Havent tried casses in php yet either, good to know.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.