'Switches state string starting with leading 1
Dim switchesState As String = "1"
Dim FasterSwitchesStateValue As Long = 1
'Add the switch state 0 or 1 to the switchesState string
For i = 0 To NumSwitches - 1
Dim n As Byte = IIf(Rnd(0,10) <= 5, 0, 1) 'just realized this is 60:40 not 50:50
switchesState = JoinStrings(Array As String(switchesState, n))
FasterSwitchesStateValue = FasterSwitchesStateValue * 10 + n 'changing 10 to 2 will pack in binary (base 2) rather than decimal (base 10) = 3x as many switches
Log("Switch ", i, "=", n)
Next
Dim switchesStateValue As Long = switchesState
Log("Sending to Domoticz ", NumSwitches, " switches with state packed as Long ", switchesStateValue, " (with leading 1)")
Log("Sending to Domoticz ", NumSwitches, " switches with state packed as Long ", FasterSwitchesStateValue, " (with leading 1)")
'Switch 0=1
'Switch 1=1
'Switch 2=0
'Switch 3=1
'Switch 4=0
'Sending To Domoticz 5 Switches with state packed As Long 111010 (with leading 1)