This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from microbit import * | |
i2c.init() | |
def drive(left,right):2 | |
if left > 255: left = 255 | |
if left < -255: left = -255 | |
if right > 255: right = 255 | |
if right < -255: right = -255 | |
if left > 0: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
In the internal Java representation a String is a sequence of 16 bit "char"s representing UTF-16 code units. | |
.getBytes converts the string to a sequence of bytes according to a specific "charset". | |
The "UTF-16" charset encodes each UTF16 code unit as a pair of bytes which may be either big endian or little endian according to the platform. To mark which byte order is in use it prepends a "byte order mark". | |
The byte order mark is the unicode code point U+FFFE. When encoded in little endian bytes this comes out to "0xFE","0xFF" which when interpreted as signed twos-complement numbers display as "-2" "-1" | |
The "UTF-16LE" charset does not use a byte-order mark. |