Serial port and pulse counter. Byte array (little-endian) to double precision

This works better, there are probably other neater ways
(again, you will have to introduce your own string)

	var testinput = "\u00a5\u0003\u0003\u0008\u0016\u0001\u00ca"
	var bytesarray = testinput.getBytes()
	logInfo("test1", "rubbish " + bytesarray.toString)
	val StringBuilder hexdisplay = new StringBuilder
	bytesarray.forEach[b |
		var int x = b.intValue.bitwiseAnd(255)
		hexdisplay.append(Integer::toHexString(x) + ", ")
		
	]
	logInfo("test2", "hex " + hexdisplay)
	val StringBuilder decdisplay = new StringBuilder
	bytesarray.forEach[b |
		var int x = b.intValue.bitwiseAnd(255)
		decdisplay.append(Integer::toString(x) + ", ")
		
	]
	logInfo("test3", "decimal " + decdisplay)

Cribbed from @Udo_Hartmann

1 Like