Recent Changes - Search:

Oktatás

* Programozás 1
  + feladatsor
  + GitHub oldal

* Szkriptnyelvek
  + feladatsor
  + quick link

Teaching

* Programming 1 (BI)
  ◇ exercises
  ◇ quick link

* Scripting Languages
  ◇ exercises
  ◇ quick link

teaching assets


Félévek

* aktuális (2023/24/2)
* archívum


Linkek

* kalendárium
   - munkaszüneti napok '20
* tételsorok
* jegyzetek
* szakdolgozat / PhD
* ösztöndíjak
* certificates
* C lang.
* C++
* C#
* Clojure
* D lang.
* Java
* Nim
* Scala


[ edit | logout ]
[ sandbox | passwd ]

20120820b

Decimal → binary conversion

Convert a decimal integer to binary format.

Example: 156 in binary format:

        quotient    remainder
156 / 2 = 78           0
78  / 2 = 39           0
39  / 2 = 19           1
19  / 2 = 9            1
9   / 2 = 4            1
4   / 2 = 2            0
2   / 2 = 1            0
1   / 2 = 0            1

That is: divide the decimal number by 2 until the quotient becomes 0. At that point the algorithm stops. Reading the remainders from bottom to top we get the binary number: 10011100.

Exercise: write a program that converts an arbitrary positive integer to binary.

Note: do this conversion manually (like above). However, there is a built-in function called bin() that can do it for you.

Cloud City

  

Blogjaim, hobbi projektjeim

* The Ubuntu Incident
* Python Adventures
* @GitHub
* heroku
* extra
* haladó Python
* YouTube listák


Debrecen | la France


[ edit ]

Edit - History - Print *** Report - Recent Changes - Search
Page last modified on 2015 June 25, 09:41