cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Try the Materials Informatics Toolkit, which is designed to easily handle SMILES data. This and other helpful add-ins are available in the JMP® Marketplace
Choose Language Hide Translation Bar
RayE
Level II

Need a script to read a single bit in am 8 bit code

Hi, I have been trying to find a way to read one bit in an 8-bit code (column RegRead) to be used to create a new column.

I can't seem to know to do it. in this example below, I am trying to ready bit[3], can someone help with it

much appreciated.

Ray

RayE_0-1650657381584.png

 

2 ACCEPTED SOLUTIONS

Accepted Solutions
Craige_Hales
Super User

Re: Need a script to read a single bit in am 8 bit code

Is that what the data looks like in a JMP data table? Is the column a character column or a numeric column? There are at least 3 different possibilities:

 

If the data is already characters, "1" and "0", then the substr() function should be able to grab the 5th character (assuming the leading "0" characters are present.) Test carefully; if you call the LSB bit 0 vs bit 1 changes the answer, and substr starts at 1, not 0.

 

If the value is a number, weirdly showing a base 10 number that looks like a base 2 number, (1) you might want to re-import it as character or (2) you might use mod(floor(RegRead/1000),2).

 

If the value is a number between 0 and 255, you might use mod(floor(RegRead/8),2). Divide by 8 shifts the bit pattern three places to the right, floor throws away the fraction, mod-2 is 1 for odd answers when the LSB is 1.

 

Another possibility might be numeric from -128 to 127 if the transfer somehow thinks the MSB is a sign bit.

Craige

View solution in original post

RayE
Level II

Re: Need a script to read a single bit in am 8 bit code

Thanks Craige

you gave the idea to use SUBSTR() function and I tested it out with random columns Test1,2,3

dt << New Column ("Extract_Bit5", formula(SUBSTR(:Test1, 5, 1)));
dt << New Column ("Extract_Bit7", formula(SUBSTR(:Test2, 1, 1)));
dt << New Column ("Extract_Bit0", formula(SUBSTR(:Test3, 8, 1)));

 

results

RayE_0-1650670513451.png

 

View solution in original post

3 REPLIES 3
Craige_Hales
Super User

Re: Need a script to read a single bit in am 8 bit code

Is that what the data looks like in a JMP data table? Is the column a character column or a numeric column? There are at least 3 different possibilities:

 

If the data is already characters, "1" and "0", then the substr() function should be able to grab the 5th character (assuming the leading "0" characters are present.) Test carefully; if you call the LSB bit 0 vs bit 1 changes the answer, and substr starts at 1, not 0.

 

If the value is a number, weirdly showing a base 10 number that looks like a base 2 number, (1) you might want to re-import it as character or (2) you might use mod(floor(RegRead/1000),2).

 

If the value is a number between 0 and 255, you might use mod(floor(RegRead/8),2). Divide by 8 shifts the bit pattern three places to the right, floor throws away the fraction, mod-2 is 1 for odd answers when the LSB is 1.

 

Another possibility might be numeric from -128 to 127 if the transfer somehow thinks the MSB is a sign bit.

Craige
RayE
Level II

Re: Need a script to read a single bit in am 8 bit code

here is actual example of columns (smaller dataset) with each column's info, the decimal column is Numeric and Binary column is a Character.

I am interested in the Binary column only; the LSB will change from 0 to 1 based on test data collected and programming of each register.

I do use this formula to convert from Dec to Binary

dt << New Column ("RegRead_Binary", formula(decimalToBinary = Hex(:RegRead, Base(2), Pad To(3))));

 

Thanks again

 

RayE_0-1650668481724.png

 

RayE
Level II

Re: Need a script to read a single bit in am 8 bit code

Thanks Craige

you gave the idea to use SUBSTR() function and I tested it out with random columns Test1,2,3

dt << New Column ("Extract_Bit5", formula(SUBSTR(:Test1, 5, 1)));
dt << New Column ("Extract_Bit7", formula(SUBSTR(:Test2, 1, 1)));
dt << New Column ("Extract_Bit0", formula(SUBSTR(:Test3, 8, 1)));

 

results

RayE_0-1650670513451.png