]> granicus.if.org Git - python/commitdiff
Added bin() builtin. I'm going to check in the tests in a seperate checkin, because...
authorEric Smith <eric@trueblade.com>
Fri, 22 Feb 2008 16:30:22 +0000 (16:30 +0000)
committerEric Smith <eric@trueblade.com>
Fri, 22 Feb 2008 16:30:22 +0000 (16:30 +0000)
Python/bltinmodule.c

index a9d68caa3dcf674bc558fdba2ad59f32be013b32..71beeba32141734633498a644606b9ab38d53eb0 100644 (file)
@@ -208,6 +208,18 @@ Deprecated since release 2.3. Instead, use the extended call syntax:\n\
     function(*args, **keywords).");
 
 
+static PyObject *
+builtin_bin(PyObject *self, PyObject *v)
+{
+        return PyNumber_ToBase(v, 2);
+}
+
+PyDoc_STRVAR(bin_doc,
+"bin(number) -> string\n\
+\n\
+Return the binary representation of an integer or long integer.");
+
+
 static PyObject *
 builtin_callable(PyObject *self, PyObject *v)
 {
@@ -2366,6 +2378,7 @@ static PyMethodDef builtin_methods[] = {
        {"all",         builtin_all,        METH_O, all_doc},
        {"any",         builtin_any,        METH_O, any_doc},
        {"apply",       builtin_apply,      METH_VARARGS, apply_doc},
+       {"bin",         builtin_bin,        METH_O, bin_doc},
        {"callable",    builtin_callable,   METH_O, callable_doc},
        {"chr",         builtin_chr,        METH_VARARGS, chr_doc},
        {"cmp",         builtin_cmp,        METH_VARARGS, cmp_doc},