Subscribe Bookmark RSS Feed

Creating Blob object

j_bonnouvrier

Community Trekker

Joined:

Dec 19, 2012

My problem is very simple but I am stuck with it: I Have a column called "Code". Let's say it is full of "3".

This column is the result of the reading of a memory encoded with 8-bit binary.

In my exemple, 3 is actually 00000011.

I would like to  convert 3 into 00000011. I tried the script:

New Column( "NEW_COLUMN", Numeric, Continuous );

Column( "NEW_COLUMN" ) <<Set Formula(Char To Blob(Char(:SERIAL_OTPB),"utf-8"));

But it fails. Any idea how to handle it?

Thanks in advance!

Jérôme

1 REPLY
txnelson

Super User

Joined:

Jun 22, 2012

Hi Jérôme,

If you use the following formula, it will create the character string you want

base = Function( {n},

{default local},

If( n != 0,

ndash = "";

digits = "0123456789ABCDEF";

While( n > 0,

remainder = Mod( n, 2 );

newdigit = Substr( digits, (1 + remainder), 1 );

ndash = newdigit || ndash;

n = (n - remainder) / 2;

);

ndash = Substr( "00000000", 1, 8 - Length( ndash ) ) || ndash;

,

Ndash = "00000000"

);base(:Code)

Assuming the target column is called "Code"

Jim

Jim