The unofficial CircuitPython Reference

bin()

description

The bin() function is used to convert an integer number to a binary string. String type with the original value expressed as a series of 1s and 0s preceded by 0b.

syntax

bin(number)

methods

parameters

number: required a integer number

(number could be a variable, but the content of the variable must be an integer number)

returns

Returns binary string of the parameter

(note: the data type of output binary string is integer)

example code

serial output:

code.py output:

Original number:  10

Binary string:0b1010


Original number:  -10

Binary string:-0b1010

see also:

No items found.