Logic Machine Forum
Value extract from Byte - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: Value extract from Byte (/showthread.php?tid=876)



Value extract from Byte - DarthPaul - 30.06.2017

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?


RE: Value extract from Byte - admin - 30.06.2017

Can be done with modulo (%) operator:
Code:
value = 253
v3 = value % 10
v2 = math.floor(value / 10) % 10
v1 = math.floor(value / 100)