<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://teaching.healthtech.dtu.dk:443/22116/index.php?action=history&amp;feed=atom&amp;title=Example_code_-_Basics</id>
	<title>Example code - Basics - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://teaching.healthtech.dtu.dk:443/22116/index.php?action=history&amp;feed=atom&amp;title=Example_code_-_Basics"/>
	<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22116/index.php?title=Example_code_-_Basics&amp;action=history"/>
	<updated>2026-04-24T16:36:37Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://teaching.healthtech.dtu.dk:443/22116/index.php?title=Example_code_-_Basics&amp;diff=33&amp;oldid=prev</id>
		<title>WikiSysop: Created page with &quot;== Decimal to Binary number converter == I am a bit unhappy about this example due to the required knowledge of binary numbers, but as such the example is great.&lt;br&gt; Youtube: [https://www.youtube.com/watch?v=2SUvWfNJSsM Binary numbers - watch from 2:00 to 6:00]&lt;br&gt; [https://en.wikipedia.org/wiki/Binary_number#Representation Wikipedia on binary numbers]  &lt;pre&gt; print(&quot;This script converts whole numbers (integers) into binary.&quot;) # Ask for user input number = int(input(&quot;Ente...&quot;</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22116/index.php?title=Example_code_-_Basics&amp;diff=33&amp;oldid=prev"/>
		<updated>2025-08-25T13:05:21Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;== Decimal to Binary number converter == I am a bit unhappy about this example due to the required knowledge of binary numbers, but as such the example is great.&amp;lt;br&amp;gt; Youtube: [https://www.youtube.com/watch?v=2SUvWfNJSsM Binary numbers - watch from 2:00 to 6:00]&amp;lt;br&amp;gt; [https://en.wikipedia.org/wiki/Binary_number#Representation Wikipedia on binary numbers]  &amp;lt;pre&amp;gt; print(&amp;quot;This script converts whole numbers (integers) into binary.&amp;quot;) # Ask for user input number = int(input(&amp;quot;Ente...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== Decimal to Binary number converter ==&lt;br /&gt;
I am a bit unhappy about this example due to the required knowledge of binary numbers, but as such the example is great.&amp;lt;br&amp;gt;&lt;br /&gt;
Youtube: [https://www.youtube.com/watch?v=2SUvWfNJSsM Binary numbers - watch from 2:00 to 6:00]&amp;lt;br&amp;gt;&lt;br /&gt;
[https://en.wikipedia.org/wiki/Binary_number#Representation Wikipedia on binary numbers]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
print(&amp;quot;This script converts whole numbers (integers) into binary.&amp;quot;)&lt;br /&gt;
# Ask for user input&lt;br /&gt;
number = int(input(&amp;quot;Enter a integer: &amp;quot;))&lt;br /&gt;
# Very basic input checking, not anticipating characters or strings&lt;br /&gt;
# Demonstrating how important proper initializing is.&lt;br /&gt;
if number == 0:&lt;br /&gt;
    binary = &amp;quot;0&amp;quot;&lt;br /&gt;
else:&lt;br /&gt;
    binary = &amp;quot;&amp;quot;&lt;br /&gt;
if number &amp;gt;= 0:&lt;br /&gt;
    sign = &amp;quot;&amp;quot;&lt;br /&gt;
    whole = number&lt;br /&gt;
else:&lt;br /&gt;
    sign = &amp;quot;-&amp;quot;&lt;br /&gt;
    whole = -number&lt;br /&gt;
&lt;br /&gt;
# The number is divided by two until we reach zero&lt;br /&gt;
# the residuals are forming the binary number, from right to left&lt;br /&gt;
# ie. the first residual will be the last in the bin. number&lt;br /&gt;
# fx. 13 -&amp;gt; 1101 : 1*8 + 1*4 + 0*2 + 1*1&lt;br /&gt;
while (whole &amp;gt; 0):&lt;br /&gt;
    residual = whole % 2&lt;br /&gt;
    whole = int(whole / 2)&lt;br /&gt;
    # Adding to the left side of the string&lt;br /&gt;
    binary = str(residual) + binary&lt;br /&gt;
&lt;br /&gt;
print(&amp;quot;Decimal&amp;quot;, number, &amp;quot;is in Binary:&amp;quot;, sign+binary)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
</feed>