NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Trying to convert a Mac address String to a number using Val function & get an OverFlow

Hi:
I'm trying to convert a mac address string to a number using Val function & do not get the right result. (I understand thar I've got an overflow). Any solutions?
0 Kudos
Message 1 of 8
(10,702 Views)
Hey ofer_o
 
Can you post an example of the string before you use it in the function?  Does it have the dashes in it?  What kind of a result are you getting?
 
Thanks,
jigg
CTA, CLA
testeract.com
~Will work for kudos and/or BBQ~
0 Kudos
Message 2 of 8
(10,682 Views)

Hi Sam:

I'm using this Testand expression to convert a mac address string to number:

Locals

.Local=val("0x1122334455ab",Locals.isvalid)

The result is:

Locals.isvalid = True

local = 4294967295

I used Windows Calculator to convert this hex number (1122334455ab) to decimal & got the result: 18838586676651.So I understand that there is an overflow problem.

0 Kudos
Message 3 of 8
(10,665 Views)

Unfortunately you can not store more than 32 bits in a Number.  Since the converted hexidecimal value returns a decimal value that is larger than 32 bits then you see the overflow like you say. 

What are you trying to do with the decimal value once you have it?  Maybe there is a better way to accomplish your goal.

Regards,

jigg
CTA, CLA
testeract.com
~Will work for kudos and/or BBQ~
0 Kudos
Message 4 of 8
(10,649 Views)
Since the first 3 bytes are what is knows as the Organizationally Unique Number and will not change from vendor to vendor, can't you just strip these off and use the rest?
0 Kudos
Message 5 of 8
(10,645 Views)
Hi
Yes, Dennis I think u right. I will strip the first 3 bytes.
Thank's u all.
Ofer
0 Kudos
Message 6 of 8
(10,636 Views)
This is only partially correct.  You can represent any 64-bit floating point number in TestStand.  The Val function only supports 32 bits for integers.  The IEEE 754 standard stores 52 bits for the mantissa, you can represent your 48-bit integer as a double just fine.  You will just have to do some math to convert it on your own.  If you convert the first 4 bytes of your string, and multiply by 2^32, then add the last 8 bytes, you will have a number that will not lose any precision.

For example, if I had my string stored at Locals.String, and I wanted the value at Locals.Num, I could use the following expression:

Locals.Num = Pow(2,32) * Val(Left(Locals.String, 6)) + Val("0x" + Right(Locals.String, 8))

Allen P.
NI
0 Kudos
Message 7 of 8
(10,632 Views)
Hi Allen
Thanks a lot for the explanation
Ofer
0 Kudos
Message 8 of 8
(10,585 Views)