This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Value extract from Byte
#1
Hello

Can someone help me with script to extract 3 decimal values from a Byte.

I want the hundred value to be represented as own value ranging from 0-2 
I want the ten-value to be represented as own value ranging from 0-9 
I want the 1-value to be represented as own value ranging from 0-9


EG: Byte 253 is divided into 
V1=2 + V2=5  + V3=3

Byte 027 is divided into 
V1=0 + V2=2 + V3=7

Would this be possible?
Reply
#2
Can be done with modulo (%) operator:
Code:
value = 253
v3 = value % 10
v2 = math.floor(value / 10) % 10
v1 = math.floor(value / 100)
Reply


Forum Jump: