<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Binary &#8211; Xojo Programming Blog</title>
	<atom:link href="https://blog.xojo.com/tag/binary/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.xojo.com</link>
	<description>Blog about the Xojo programming language and IDE</description>
	<lastBuildDate>Wed, 07 Jan 2026 16:01:52 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
	<item>
		<title>The Beauty of Binary Searches</title>
		<link>https://blog.xojo.com/2025/12/16/the-beauty-of-binary-searches/</link>
		
		<dc:creator><![CDATA[Kem Tekinay]]></dc:creator>
		<pubDate>Tue, 16 Dec 2025 17:14:00 +0000</pubDate>
				<category><![CDATA[Guest Post]]></category>
		<category><![CDATA[Binary]]></category>
		<category><![CDATA[Software Development]]></category>
		<guid isPermaLink="false">https://blog.xojo.com/?p=15715</guid>

					<description><![CDATA[Problem: you need to search an array to see if it contains a particular value. The simple solution is IndexOf if it’s a simple array, or a&#8230;]]></description>
										<content:encoded><![CDATA[
<p>Problem: you need to search an array to see if it contains a particular value. The simple solution is <code>IndexOf</code> if it’s a simple array, or a loop like this:</p>



<pre class="wp-block-code"><code>for each item as ArrayType in myArray
  if item.Matches( myValue ) then
    YesSiree( myValue )
    exit
  end if
next</code></pre>



<p>That’s pretty easy, but what if the array is really big? And what if you have to do this many times?</p>



<p>For example, let’s say your array has 10,000 items. For each value that doesn’t match, your code will have to do 10,000 comparisons. But, if your array can be sorted, you can perform that task with, at most, 14 comparisons using a binary search.</p>



<p>The concept is simple: you take an ordered list and start in the middle. If what you’re trying to match is less than that point, you discard the upper half of the list, then start again at the midpoint of the rest. By continuously cutting the list in half, you will do, at most,&nbsp;<code>Ceil(Log2(arrayCount))</code>&nbsp;comparisons per value.</p>



<p>For simplicity’s sake, let’s say you want to search an array of strings. (Yes, a&nbsp;<code>Dictionary</code>&nbsp;would be the better choice here, but this is just for illustration.) The code would look something like this:</p>



<pre class="wp-block-code"><code>myArray.Sort

var firstIndex as integer = 0
var lastIndex as integer = myArray.LastIndex

while firstIndex &lt;= lastIndex
  var midPoint as integer = ( lastIndex - firstIndex ) \ 2 + firstIndex

  var compare as string = myArray( midPoint )

  if myValue = compare then
    YesSiree( myValue )
    exit
  end if

  if myValue &lt; compare then
    lastIndex = midPoint - 1
  else
    firstIndex = midPoint + 1
  end if
wend</code></pre>



<p>With that 10,000-item array, the first loop would look at item 5,000. If&nbsp;<code>myValue</code>&nbsp;is greater than that, it would next look at item 7,500. Still greater? Now it will look at item 8,750, and so on. The entire array will be processed efficiently with large chunks never needing examination at all. If you have to do this for 1,000 different values, you will end with, at most, 14,000 comparisons instead of 10&nbsp;million.</p>



<p>Quite the savings, right?</p>



<p><em>Kem Tekinay is a Mac consultant and programmer who has been using Xojo since its first release to create custom solutions for clients. He is the author of the popular utilities <a href="http://www.mactechnologies.com/index.php?page=downloads#tftpclient" target="_blank" rel="noreferrer noopener">TFTP Client</a> and <a href="http://www.mactechnologies.com/index.php?page=downloads#regexrx" target="_blank" rel="noreferrer noopener">RegExRX</a> (both written with Xojo) and lives in Connecticut with his wife Lisa, and their cat.</em></p>



<ul class="wp-block-social-links has-normal-icon-size is-content-justification-center is-layout-flex wp-container-core-social-links-is-layout-16018d1d wp-block-social-links-is-layout-flex"><li class="wp-social-link wp-social-link-facebook  wp-block-social-link"><a rel="noopener nofollow" target="_blank" href="https://www.facebook.com/goxojo" class="wp-block-social-link-anchor"><svg width="24" height="24" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M12 2C6.5 2 2 6.5 2 12c0 5 3.7 9.1 8.4 9.9v-7H7.9V12h2.5V9.8c0-2.5 1.5-3.9 3.8-3.9 1.1 0 2.2.2 2.2.2v2.5h-1.3c-1.2 0-1.6.8-1.6 1.6V12h2.8l-.4 2.9h-2.3v7C18.3 21.1 22 17 22 12c0-5.5-4.5-10-10-10z"></path></svg><span class="wp-block-social-link-label screen-reader-text">Facebook</span></a></li>

<li class="wp-social-link wp-social-link-x  wp-block-social-link"><a rel="noopener nofollow" target="_blank" href="https://x.com/xojo" class="wp-block-social-link-anchor"><svg width="24" height="24" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M13.982 10.622 20.54 3h-1.554l-5.693 6.618L8.745 3H3.5l6.876 10.007L3.5 21h1.554l6.012-6.989L15.868 21h5.245l-7.131-10.378Zm-2.128 2.474-.697-.997-5.543-7.93H8l4.474 6.4.697.996 5.815 8.318h-2.387l-4.745-6.787Z" /></svg><span class="wp-block-social-link-label screen-reader-text">X</span></a></li>

<li class="wp-social-link wp-social-link-linkedin  wp-block-social-link"><a rel="noopener nofollow" target="_blank" href="https://www.linkedin.com/company/xojo" class="wp-block-social-link-anchor"><svg width="24" height="24" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M19.7,3H4.3C3.582,3,3,3.582,3,4.3v15.4C3,20.418,3.582,21,4.3,21h15.4c0.718,0,1.3-0.582,1.3-1.3V4.3 C21,3.582,20.418,3,19.7,3z M8.339,18.338H5.667v-8.59h2.672V18.338z M7.004,8.574c-0.857,0-1.549-0.694-1.549-1.548 c0-0.855,0.691-1.548,1.549-1.548c0.854,0,1.547,0.694,1.547,1.548C8.551,7.881,7.858,8.574,7.004,8.574z M18.339,18.338h-2.669 v-4.177c0-0.996-0.017-2.278-1.387-2.278c-1.389,0-1.601,1.086-1.601,2.206v4.249h-2.667v-8.59h2.559v1.174h0.037 c0.356-0.675,1.227-1.387,2.526-1.387c2.703,0,3.203,1.779,3.203,4.092V18.338z"></path></svg><span class="wp-block-social-link-label screen-reader-text">LinkedIn</span></a></li>

<li class="wp-social-link wp-social-link-github  wp-block-social-link"><a rel="noopener nofollow" target="_blank" href="https://github.com/topics/xojo" class="wp-block-social-link-anchor"><svg width="24" height="24" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M12,2C6.477,2,2,6.477,2,12c0,4.419,2.865,8.166,6.839,9.489c0.5,0.09,0.682-0.218,0.682-0.484 c0-0.236-0.009-0.866-0.014-1.699c-2.782,0.602-3.369-1.34-3.369-1.34c-0.455-1.157-1.11-1.465-1.11-1.465 c-0.909-0.62,0.069-0.608,0.069-0.608c1.004,0.071,1.532,1.03,1.532,1.03c0.891,1.529,2.341,1.089,2.91,0.833 c0.091-0.647,0.349-1.086,0.635-1.337c-2.22-0.251-4.555-1.111-4.555-4.943c0-1.091,0.39-1.984,1.03-2.682 C6.546,8.54,6.202,7.524,6.746,6.148c0,0,0.84-0.269,2.75,1.025C10.295,6.95,11.15,6.84,12,6.836 c0.85,0.004,1.705,0.114,2.504,0.336c1.909-1.294,2.748-1.025,2.748-1.025c0.546,1.376,0.202,2.394,0.1,2.646 c0.64,0.699,1.026,1.591,1.026,2.682c0,3.841-2.337,4.687-4.565,4.935c0.359,0.307,0.679,0.917,0.679,1.852 c0,1.335-0.012,2.415-0.012,2.741c0,0.269,0.18,0.579,0.688,0.481C19.138,20.161,22,16.416,22,12C22,6.477,17.523,2,12,2z"></path></svg><span class="wp-block-social-link-label screen-reader-text">GitHub</span></a></li>

<li class="wp-social-link wp-social-link-youtube  wp-block-social-link"><a rel="noopener nofollow" target="_blank" href="https://www.youtube.com/c/XojoInc" class="wp-block-social-link-anchor"><svg width="24" height="24" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M21.8,8.001c0,0-0.195-1.378-0.795-1.985c-0.76-0.797-1.613-0.801-2.004-0.847c-2.799-0.202-6.997-0.202-6.997-0.202 h-0.009c0,0-4.198,0-6.997,0.202C4.608,5.216,3.756,5.22,2.995,6.016C2.395,6.623,2.2,8.001,2.2,8.001S2,9.62,2,11.238v1.517 c0,1.618,0.2,3.237,0.2,3.237s0.195,1.378,0.795,1.985c0.761,0.797,1.76,0.771,2.205,0.855c1.6,0.153,6.8,0.201,6.8,0.201 s4.203-0.006,7.001-0.209c0.391-0.047,1.243-0.051,2.004-0.847c0.6-0.607,0.795-1.985,0.795-1.985s0.2-1.618,0.2-3.237v-1.517 C22,9.62,21.8,8.001,21.8,8.001z M9.935,14.594l-0.001-5.62l5.404,2.82L9.935,14.594z"></path></svg><span class="wp-block-social-link-label screen-reader-text">YouTube</span></a></li></ul>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Free Xojo Linux and Raspberry Pi for Everyone</title>
		<link>https://blog.xojo.com/2024/03/26/free-linux-builds/</link>
		
		<dc:creator><![CDATA[Xojo]]></dc:creator>
		<pubDate>Tue, 26 Mar 2024 15:26:18 +0000</pubDate>
				<category><![CDATA[Community]]></category>
		<category><![CDATA[Desktop]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Source Control]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[2024r1]]></category>
		<category><![CDATA[ARM]]></category>
		<category><![CDATA[Beginner Tips]]></category>
		<category><![CDATA[Binary]]></category>
		<category><![CDATA[GitHub]]></category>
		<category><![CDATA[GitLab]]></category>
		<category><![CDATA[Rapid Application Development]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Version Control]]></category>
		<category><![CDATA[Xojo Programming Language]]></category>
		<guid isPermaLink="false">https://blog.xojo.com/?p=12631</guid>

					<description><![CDATA[Now with Xojo 2024r1 you can use Xojo's free IDE to build Linux desktop and console apps from Linux, macOS, or Windows, no license required.]]></description>
										<content:encoded><![CDATA[
<p>Beginning with Xojo 2024r1 you can use Xojo&#8217;s free IDE to build Linux desktop and console apps from Linux, macOS, or Windows, no license required.</p>



<h2 class="wp-block-heading" id="free-linux">Xojo Linux is Free</h2>



<p>We have made building for Linux free and included in the Xojo IDE! This means that on Linux you get a version control ready IDE, along with the ability to build desktop and console Linux apps (including Raspberry Pi), all for free. Launch Xojo 2024r1 (or any later release of <a href="https://xojo.com/download/" target="_blank" rel="noreferrer noopener">Xojo</a>) and open any desktop or console project, go to Build Settings, select Linux and in the Inspector choose the appropriate Architecture that matches the Linux OS you want your app to work on, either ARM or x86. Click Build to compile your project to a standalone app that you can then run on Linux &#8211; no license required.</p>



<h2 class="wp-block-heading">Wrapping Up</h2>



<p>All these changes were made based on feedback from the Xojo community and to better match the changing ways that people develop and share software projects. With this change Xojo continues its dedication to supporting Linux.</p>



<p><a href="https://xojo.com/download/">Download Xojo</a> to get started.</p>



<p>Edited 07/2025 to reflect changes to licensing. </p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>How a Binary Enum Simplifies a Calendar Week Day Selector</title>
		<link>https://blog.xojo.com/2021/09/28/how-a-binary-enum-simplifies-a-calendar-week-day-selector/</link>
		
		<dc:creator><![CDATA[Wayne Golding]]></dc:creator>
		<pubDate>Tue, 28 Sep 2021 13:00:00 +0000</pubDate>
				<category><![CDATA[Community]]></category>
		<category><![CDATA[Cross-Platform]]></category>
		<category><![CDATA[Desktop]]></category>
		<category><![CDATA[Guest Post]]></category>
		<category><![CDATA[Learning]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Beginner Tips]]></category>
		<category><![CDATA[Binary]]></category>
		<category><![CDATA[Enumeration]]></category>
		<category><![CDATA[Rapid Application Development]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Xojo Programming Language]]></category>
		<guid isPermaLink="false">https://blog.xojo.com/?p=9332</guid>

					<description><![CDATA[In Xojo 2021R2 binary enumerations were introduced. These Enums must be declared in a module and are treated by the compiler as a class. Learn to create an Enum for Days of the Week and demonstrate the use of that by creating a custom segmented button control.]]></description>
										<content:encoded><![CDATA[
<p>In Xojo 2021R2 binary enumerations were introduced.&nbsp;These Enums must be declared in a module and are treated by the compiler as a class.&nbsp;Xojo documentation for Enums can be found at <a href="http://documentation.xojo.com/api/data_types/enumeration.html">Enumeration &#8211; Xojo Documentation</a>.</p>



<p>I&#8217;d like to show you how to create an Enum for Days of the Week and demonstrate the use of that by creating a custom segmented button control.</p>



<p>Open Xojo and create a new Desktop Project.&nbsp; Insert a module and give it a name – I called mine Enumerations.</p>



<figure class="wp-block-image size-full is-style-default"><img fetchpriority="high" decoding="async" width="384" height="222" src="https://blog.xojo.com/wp-content/uploads/2021/09/image.png" alt="" class="wp-image-9335" srcset="https://blog.xojo.com/wp-content/uploads/2021/09/image.png 384w, https://blog.xojo.com/wp-content/uploads/2021/09/image-300x173.png 300w" sizes="(max-width: 384px) 100vw, 384px" /></figure>



<p>Next, add an enumeration.</p>



<figure class="wp-block-image size-full is-style-default"><img decoding="async" width="514" height="624" src="https://blog.xojo.com/wp-content/uploads/2021/09/image-1.png" alt="" class="wp-image-9336" srcset="https://blog.xojo.com/wp-content/uploads/2021/09/image-1.png 514w, https://blog.xojo.com/wp-content/uploads/2021/09/image-1-247x300.png 247w" sizes="(max-width: 514px) 100vw, 514px" /></figure>



<p>Call this Enum DaysOfWeek and make it a binary enum.</p>



<figure class="wp-block-image size-full is-style-default"><img decoding="async" width="322" height="208" src="https://blog.xojo.com/wp-content/uploads/2021/09/image-2.png" alt="" class="wp-image-9337" srcset="https://blog.xojo.com/wp-content/uploads/2021/09/image-2.png 322w, https://blog.xojo.com/wp-content/uploads/2021/09/image-2-300x194.png 300w" sizes="(max-width: 322px) 100vw, 322px" /></figure>



<p>Next, fill in the Declarations.</p>



<figure class="wp-block-image size-full is-style-default"><img loading="lazy" decoding="async" width="270" height="376" src="https://blog.xojo.com/wp-content/uploads/2021/09/image-3.png" alt="" class="wp-image-9338" srcset="https://blog.xojo.com/wp-content/uploads/2021/09/image-3.png 270w, https://blog.xojo.com/wp-content/uploads/2021/09/image-3-215x300.png 215w" sizes="auto, (max-width: 270px) 100vw, 270px" /></figure>



<p>Next, I’m going to add a bunch of Constants to the module, one for each day of the week.&nbsp; This will allow me to localise the control later.</p>



<figure class="wp-block-image size-full is-style-default"><img loading="lazy" decoding="async" width="358" height="276" src="https://blog.xojo.com/wp-content/uploads/2021/09/image-4.png" alt="" class="wp-image-9339" srcset="https://blog.xojo.com/wp-content/uploads/2021/09/image-4.png 358w, https://blog.xojo.com/wp-content/uploads/2021/09/image-4-300x231.png 300w" sizes="auto, (max-width: 358px) 100vw, 358px" /></figure>



<p>Now I’ll add a convenience method called ToString that will extend the DaysOfWeek Enum.</p>



<figure class="wp-block-image size-full is-style-default"><img loading="lazy" decoding="async" width="382" height="338" src="https://blog.xojo.com/wp-content/uploads/2021/09/image-5.png" alt="" class="wp-image-9340" srcset="https://blog.xojo.com/wp-content/uploads/2021/09/image-5.png 382w, https://blog.xojo.com/wp-content/uploads/2021/09/image-5-300x265.png 300w" sizes="auto, (max-width: 382px) 100vw, 382px" /></figure>



<p>The code in this method is:</p>



<pre class="wp-block-preformatted">Var SelectedDays() As String

Var d As DaysOfWeek

d = DaysOfWeek.Sunday
If Value.Contains(d) Then
  SelectedDays.Add(Day1)
End If

d = DaysOfWeek.Monday
If Value.Contains(d) Then
  SelectedDays.Add(Day2)
End If

d = DaysOfWeek.Tuesday
If Value.Contains(d) Then
  SelectedDays.Add(Day3)
End If

d = DaysOfWeek.Wednesday
If Value.Contains(d) Then
  SelectedDays.Add(Day4)
End If

d = DaysOfWeek.Thursday
If Value.Contains(d) Then
  SelectedDays.Add(Day5)
End If

d = DaysOfWeek.Friday
If Value.Contains(d) Then
  SelectedDays.Add(Day6)
End If

d = DaysOfWeek.Saturday
If Value.Contains(d) Then
  SelectedDays.Add(Day7)
End If

Return String.FromArray(SelectedDays, ", ")</pre>



<p>You can see from this code that it is possible to include multiple days in this Enum.&nbsp; The return string might be “Sunday, Monday, Friday” for example.</p>



<p>Create the DaysOfWeek Control by dragging a segmented button from the library to the navigator and naming it DaysOfWeekControl.</p>



<figure class="wp-block-image size-full is-style-default"><img loading="lazy" decoding="async" width="292" height="62" src="https://blog.xojo.com/wp-content/uploads/2021/09/image-6.png" alt="" class="wp-image-9341"/></figure>



<p>Then use the Inspector Behaviour option to customise the control.</p>



<figure class="wp-block-image size-full is-style-default"><img loading="lazy" decoding="async" width="592" height="700" src="https://blog.xojo.com/wp-content/uploads/2021/09/image-7.png" alt="" class="wp-image-9342" srcset="https://blog.xojo.com/wp-content/uploads/2021/09/image-7.png 592w, https://blog.xojo.com/wp-content/uploads/2021/09/image-7-254x300.png 254w" sizes="auto, (max-width: 592px) 100vw, 592px" /></figure>



<p>Change the default width to 500 and the selection style to 1 for multiple</p>



<figure class="wp-block-image size-full is-style-default"><img loading="lazy" decoding="async" width="790" height="700" src="https://blog.xojo.com/wp-content/uploads/2021/09/image-8.png" alt="" class="wp-image-9343" srcset="https://blog.xojo.com/wp-content/uploads/2021/09/image-8.png 790w, https://blog.xojo.com/wp-content/uploads/2021/09/image-8-300x266.png 300w, https://blog.xojo.com/wp-content/uploads/2021/09/image-8-768x681.png 768w" sizes="auto, (max-width: 790px) 100vw, 790px" /></figure>



<p>Unfortunately, we can’t edit the segments here as the control is a textfield, not a textarea and the edit button is missing.&nbsp; But we can edit the source file (you need a license capable of saving the project in text format).&nbsp; Save and close the project, and open the DaysOfWeekControl.xojo_code file in Notepad, search for “One” which will find the initial value of the control.</p>



<figure class="wp-block-image size-full is-style-default"><img loading="lazy" decoding="async" width="360" height="34" src="https://blog.xojo.com/wp-content/uploads/2021/09/image-15.png" alt="" class="wp-image-9351" srcset="https://blog.xojo.com/wp-content/uploads/2021/09/image-15.png 360w, https://blog.xojo.com/wp-content/uploads/2021/09/image-15-300x28.png 300w" sizes="auto, (max-width: 360px) 100vw, 360px" /></figure>



<p>You can see each segment is separated with “\r” which the IDE translates to &lt;CR&gt;.&nbsp; Replace &#8220;One\rTwo&#8221; with &#8220;#Day1\r#Day2\r#Day3\r#Day4\r#Day5\r#Day6\r#Day7&#8221; which will tell the compiler to use the localised Day constants created earlier.&nbsp;Save the code file and reopen the project.</p>



<p>Now we can continue customising the control first adding a computed property Value As DaysOfWeek. In the Get method add this code:</p>



<pre class="wp-block-preformatted">Var Result As DaysOfWeek = 0 ' The default value is set to create an instance of Result
For i As Integer = 0 To 6 ' Each Segment in the control
  If me.SegmentAt(i).Selected Then
    Var d As DaysOfWeek = 2 ^ i ' Converts the index (i) to the binary number that matches the value of the enum
    Result = Result Or d ' Adds the selected day to the enum
  End If
Next i

Return Result</pre>



<p>You’ll notice the first line sets the value of Result to 0, this is important as otherwise the variable will be Nil – remember this is being rendered as a class by the compiler.</p>



<p>In the Set Method place this code:</p>



<pre class="wp-block-preformatted">For i As Integer = 0 To 6 ' Index of each segment
&nbsp; Var d As DaysOfWeek = 2 ^ i ' Convert the index (i) to binary
&nbsp; me.SegmentAt(i).Selected = value.Contains(d) ' Set the selected state of the button
Next i

RaiseEvent ValueChanged(value)</pre>



<p>This will show the button as pressed or not depending on whether the day is included on the value.&nbsp; Now add an event definition.</p>



<figure class="wp-block-image size-full is-style-default"><img loading="lazy" decoding="async" width="358" height="288" src="https://blog.xojo.com/wp-content/uploads/2021/09/image-9.png" alt="" class="wp-image-9344" srcset="https://blog.xojo.com/wp-content/uploads/2021/09/image-9.png 358w, https://blog.xojo.com/wp-content/uploads/2021/09/image-9-300x241.png 300w" sizes="auto, (max-width: 358px) 100vw, 358px" /></figure>



<p>Which will raise when a button is pressed, which means we need to handle the pressed event of the control.</p>



<pre class="wp-block-preformatted">Sub Pressed(segmentIndex as integer) Handles Pressed
&nbsp; #Pragma Unused segmentIndex

&nbsp; RaiseEvent ValueChanged(Value)
&nbsp;End Sub</pre>



<p>Time to use the control.&nbsp;We want to place a copy of the control onto Window1; we can either drag the control from the Navigator or select it from the Library (it will show in the Project Controls section).&nbsp;I’m also going to add a label to the Window under the DaysofWeek control, name it SelectedDaysLabel and make it the same width as the control (500).&nbsp;This will be where we will show the result of the days selected.</p>



<figure class="wp-block-image size-full is-style-default"><img loading="lazy" decoding="async" width="818" height="210" src="https://blog.xojo.com/wp-content/uploads/2021/09/image-10.png" alt="" class="wp-image-9345" srcset="https://blog.xojo.com/wp-content/uploads/2021/09/image-10.png 818w, https://blog.xojo.com/wp-content/uploads/2021/09/image-10-300x77.png 300w, https://blog.xojo.com/wp-content/uploads/2021/09/image-10-768x197.png 768w" sizes="auto, (max-width: 818px) 100vw, 818px" /></figure>



<p>Next, handle the ValueChanged event on the control:</p>



<pre class="wp-block-preformatted">Sub ValueChanged(Value As DaysOfWeek) Handles ValueChanged<br>&nbsp; SelectedDaysLabel.Text = Value.ToString<br>End Sub</pre>



<p>When we run the project and select some days, we’ll see something similar to the following.</p>



<figure class="wp-block-image size-full is-style-default"><img loading="lazy" decoding="async" width="796" height="174" src="https://blog.xojo.com/wp-content/uploads/2021/09/image-11.png" alt="" class="wp-image-9346" srcset="https://blog.xojo.com/wp-content/uploads/2021/09/image-11.png 796w, https://blog.xojo.com/wp-content/uploads/2021/09/image-11-300x66.png 300w, https://blog.xojo.com/wp-content/uploads/2021/09/image-11-768x168.png 768w" sizes="auto, (max-width: 796px) 100vw, 796px" /></figure>



<p>Now to show the power of the binary enum I’m going to add another declaration to the Enumeration “WeekDays” with a value of 62</p>



<figure class="wp-block-image size-full is-style-default"><img loading="lazy" decoding="async" width="238" height="410" src="https://blog.xojo.com/wp-content/uploads/2021/09/image-12.png" alt="" class="wp-image-9347" srcset="https://blog.xojo.com/wp-content/uploads/2021/09/image-12.png 238w, https://blog.xojo.com/wp-content/uploads/2021/09/image-12-174x300.png 174w" sizes="auto, (max-width: 238px) 100vw, 238px" /></figure>



<p>62 is the total of the values for Monday through Friday.&nbsp;Once we have this, we can add a button to the window and set its “Pressed” event handler to:</p>



<pre class="wp-block-preformatted">Sub Pressed() Handles Pressed<br>&nbsp; DaysOfWeekControl1.Value = DaysOfWeek.Weekdays<br>End Sub</pre>



<p>Pressing the button will result in:</p>



<figure class="wp-block-image size-full is-style-default"><img loading="lazy" decoding="async" width="808" height="226" src="https://blog.xojo.com/wp-content/uploads/2021/09/image-13.png" alt="" class="wp-image-9348" srcset="https://blog.xojo.com/wp-content/uploads/2021/09/image-13.png 808w, https://blog.xojo.com/wp-content/uploads/2021/09/image-13-300x84.png 300w, https://blog.xojo.com/wp-content/uploads/2021/09/image-13-768x215.png 768w" sizes="auto, (max-width: 808px) 100vw, 808px" /></figure>



<p>Taking this further we can add the enum value to the DateTime class by adding another Extension method to the module as below.</p>



<pre class="wp-block-preformatted">Public Function DayOfWeekEnum(Extends Value As DateTime) As DaysOfWeek&nbsp; 

  Var Result As DaysOfWeek = 2 ^ (Value.DayOfWeek - 1)
&nbsp; Return Result

End Function</pre>



<p>We need to subtract 1 from the DayOfWeek property of the passed DateTime object as the days are 1 based not 0 as in the control.&nbsp;To demonstrate how this works I’m going to add a multiline label to the window called SelectedDatesLabel and set that to show which dates over the next week have been selected by updating the ValueChanged handler as below:</p>



<pre class="wp-block-preformatted">Sub ValueChanged(Value As DaysOfWeek) Handles ValueChanged

SelectedDaysLabel.Text = Value.ToString

SelectedDatesLabel.Text = ""

For i As Integer = 1 To 7 ' From tomorrow for a week
 Var dt As DateTime = DateTime.Now.AddInterval(0, 0, i)
 If Value.Contains(dt.DayOfWeekEnum) Then
  SelectedDatesLabel.Text = SelectedDatesLabel.Text + _
  dt.ToString(DateTime.FormatStyles.Short, DateTime.FormatStyles.None) _
  + EndOfLine
    End If
  Next i

End Sub</pre>



<figure class="wp-block-image size-full is-style-default"><img loading="lazy" decoding="async" width="810" height="394" src="https://blog.xojo.com/wp-content/uploads/2021/09/image-14.png" alt="" class="wp-image-9349" srcset="https://blog.xojo.com/wp-content/uploads/2021/09/image-14.png 810w, https://blog.xojo.com/wp-content/uploads/2021/09/image-14-300x146.png 300w, https://blog.xojo.com/wp-content/uploads/2021/09/image-14-768x374.png 768w" sizes="auto, (max-width: 810px) 100vw, 810px" /></figure>



<p>That’s it folks, hope you enjoyed this tutorial.</p>



<p><em>Wayne Golding has been a Xojo developer since 2005 and is a Xojo MVP. He operates the IT Company <a href="http://www.axisdirect.nz">Axis Direct Ltd </a>which primarily develops applications using Xojo that integrate with Xero www.xero.com. Wayne’s hobby is robotics where he uses Xojo to build applications for his Raspberry Pi, often implementing IoT for remote control.</em></p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Enumeration Enhancements</title>
		<link>https://blog.xojo.com/2021/07/22/enumeration-enhancements/</link>
		
		<dc:creator><![CDATA[Greg O'Lone]]></dc:creator>
		<pubDate>Thu, 22 Jul 2021 11:48:00 +0000</pubDate>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Binary]]></category>
		<category><![CDATA[Enumeration]]></category>
		<category><![CDATA[IDE]]></category>
		<guid isPermaLink="false">https://blog.xojo.com/?p=8855</guid>

					<description><![CDATA[Xojo 2021r2 introduces a couple of enhancements to Enumerations in Xojo. The enumeration editor now shows a preview of what the value will be so there's no more guessing or counting. In addition, we've added a new Binary option which allows you to automatically create sets that aren't mutually exclusive. ]]></description>
										<content:encoded><![CDATA[
<p>Xojo 2021r2 introduces a couple of enhancements to <a href="https://documentation.xojo.com/getting_started/using_the_xojo_language/enumerations.html">enumerations</a> in Xojo. The enumeration editor now shows a preview of what the value will be so there&#8217;s no more guessing or counting.</p>



<div class="wp-block-image"><figure class="aligncenter size-large is-resized"><img loading="lazy" decoding="async" src="https://blog.xojo.com/wp-content/uploads/2021/07/image-1.png" alt="" class="wp-image-8857" width="156" height="240" srcset="https://blog.xojo.com/wp-content/uploads/2021/07/image-1.png 276w, https://blog.xojo.com/wp-content/uploads/2021/07/image-1-195x300.png 195w" sizes="auto, (max-width: 156px) 100vw, 156px" /><figcaption>Example of Enumeration with default values showing</figcaption></figure></div>



<p>In addition, we&#8217;ve added a new Binary option which allows you to automatically create sets that aren&#8217;t mutually exclusive. That is, the values of the elements are automatically powers of two and can have binary operations applied to them:</p>



<div class="wp-block-image"><figure class="aligncenter size-large is-resized"><img loading="lazy" decoding="async" src="https://blog.xojo.com/wp-content/uploads/2021/07/image-3.png" alt="" class="wp-image-8859" width="162" height="236" srcset="https://blog.xojo.com/wp-content/uploads/2021/07/image-3.png 284w, https://blog.xojo.com/wp-content/uploads/2021/07/image-3-206x300.png 206w" sizes="auto, (max-width: 162px) 100vw, 162px" /><figcaption>Example of Binary Enumeration default values</figcaption></figure></div>



<p>This new feature comes with the requirement that they be placed inside a Module because they&#8217;re rendered into your project as a Class. The reason for this is that these classes automatically have some helper methods on them to make working with the binary data easier.</p>



<ul class="wp-block-list"><li>An Operator_Convert which takes an Integer:<br><code>Var x as MyEnum = 3 // MyEnum.George, MyEnum.John</code><br></li><li>&#8230;as well as one that returns an integer:<br><code>Var y as Integer = MyEnum.George // y = 2</code><br></li><li>Automatic conversion to and from Integer:<br><code>Var x as Integer = MyEnum.Ringo // x = 4</code><br></li><li>Binary operations And, Or and Xor:<br><code>Var x as MyEnum = MyEnum.Paul Or MyEnum.Mary // x has a value of 40</code><br></li><li>Equality operations so you can compare the internal value of one instance to another:<br><code>Var x as MyEnum = MyEnum.Paul<br>Var y as MyEnum = MyEnum.Ringo<br>If x = y Then</code><br></li><li>Contains helper method:<br><code>If x.Contains(MyEnum.Peter) Then</code><br></li><li>A Read-Only Value property so you can see the internal value in the debugger</li></ul>



<p>Just like regular Enumerations, the editor also allows you to explicitly specify the value of an element:</p>



<div class="wp-block-image"><figure class="aligncenter size-large is-resized"><img loading="lazy" decoding="async" src="https://blog.xojo.com/wp-content/uploads/2021/07/image-5.png" alt="" class="wp-image-8862" width="157" height="226" srcset="https://blog.xojo.com/wp-content/uploads/2021/07/image-5.png 338w, https://blog.xojo.com/wp-content/uploads/2021/07/image-5-209x300.png 209w" sizes="auto, (max-width: 157px) 100vw, 157px" /></figure></div>



<p>This is so instead of having to write: <br><code>Var x as MyEnum = MyEnum.George Or MyEnum.John Or MyEnum.Ringo Or MyEnum.Paul</code><br><br>You can simply write:<br><code>Var x as MyEnum = MyEnum.TheBeatles</code><br><br>We hope that you&#8217;ll enjoy this feature as much as we do!</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Binary Magic with Signed Integers</title>
		<link>https://blog.xojo.com/2019/02/27/binary-magic-with-signed-integers/</link>
		
		<dc:creator><![CDATA[Norman Palardy]]></dc:creator>
		<pubDate>Wed, 27 Feb 2019 10:00:22 +0000</pubDate>
				<category><![CDATA[Learning]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Binary]]></category>
		<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Xojo Programming Language]]></category>
		<guid isPermaLink="false">https://blog.xojo.com/?p=5436</guid>

					<description><![CDATA[In binary the high bit (the one immediately following the &#038;b in Xojo code) is the "sign bit". When it's set to 1, the value is interpreted as "negative" and when it's set to 0, the value is "positive". Meaning that bit is not used as part of the "number" itself.]]></description>
										<content:encoded><![CDATA[<p>In binary the high bit (the one immediately following the &amp;b in Xojo code) is the &#8220;sign bit&#8221;. When it&#8217;s set to 1, the value is interpreted as &#8220;negative&#8221; and when it&#8217;s set to 0, the value is &#8220;positive&#8221;. Meaning that bit is <em>not</em> used as part of the &#8220;number&#8221; itself.</p>
<p><span id="more-5436"></span></p>
<p>So if we start counting up values are written as:</p>
<pre>1 =&gt; &amp;b00000001
2 =&gt; &amp;b00000010
3 =&gt; &amp;b00000011</pre>
<p>and so on until we get to:</p>
<pre>127 =&gt; &amp;b01111111</pre>
<p>Now, what&#8217;s the &#8220;next number&#8221;? That would be:</p>
<pre>&amp;b10000000</pre>
<p>which this code:</p>
<pre>Dim i As Int8 = &amp;b10000000</pre>
<p>tells you is -128.</p>
<p>What does -128 look like in something like an Int16?</p>
<pre>Dim i8 As Int8 = &amp;b10000000
Dim i16 As Int16 = i8

System.DebugLog(Bin(i8)) // &lt;&lt;&lt; shows 10000000
System.DebugLog(Bin(i16)) // &lt;&lt;&lt; shows 1111111110000000</pre>
<p>Why is the int16 have all those 1&#8217;s at the beginning? It&#8217;s because if you assign:</p>
<pre>Dim i16 As Int16 = &amp;b1000000000000000</pre>
<p>you&#8217;ll find that this is -32768 or the smallest value an Int16 can hold. When you assign a little value like -128 the &#8220;lowest&#8221; 8-bit can be copied from the int8 form and the upper 8 bits have to be copies of the &#8220;sign bit&#8221; &#8211; that first one after the &#8220;&amp;b&#8221;.</p>
<p>This is called <a href="https://en.wikipedia.org/wiki/Sign_extension">sign extension</a> and is required when you move a smaller type into a larger one &#8212; like moving an Int8 into an Int16 or an Int8 into an Int32.</p>
<p>Failing to do this for <em>signed</em> values (i.e. if the code did something like &#8220;fill the upper part with 0s&#8221;):</p>
<pre>Dim i8 As Int8 = &amp;b10000000
System.DebugLog(Bin(i8))

Dim i16 As Int16 = &amp;b0000000010000000
System.DebugLog(Bin(i16))</pre>
<p>would have the Int8 value saying it held -128 and the Int16 saying it held 128 (<em>note the sign change!</em>) and this would totally wreck trying to do any math.</p>
<p>Remember this is all necessary in order to manage the sign of an integer. It is not necessary with unsigned types such as UInt8, UInt16, etc.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Binary Basics: 10 Types of People</title>
		<link>https://blog.xojo.com/2018/02/21/binary-basics-10-types-of-people/</link>
		
		<dc:creator><![CDATA[Paul Lefebvre]]></dc:creator>
		<pubDate>Wed, 21 Feb 2018 07:00:09 +0000</pubDate>
				<category><![CDATA[Fun]]></category>
		<category><![CDATA[Learning]]></category>
		<category><![CDATA[Beginner Tips]]></category>
		<category><![CDATA[Binary]]></category>
		<category><![CDATA[Citizen Developer]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Software Development]]></category>
		<guid isPermaLink="false">https://blog.xojo.com/?p=3930</guid>

					<description><![CDATA[As the old joke goes, “There are 10 types of people, those that understand how binary numbers work and those that don’t.” Let’s get you into the “understand” group. Binary is the type of numbering system that is native to computers. It is base-2. Numbers that normal people work with are called decimal or base-10.]]></description>
										<content:encoded><![CDATA[<p>As the <a href="https://en.wikipedia.org/wiki/Mathematical_joke#Jokes_with_numeral_bases">old joke goes</a>, “There are 10 types of people, those that understand how binary numbers work and those that don’t.” Let’s get you into the “understand” group.</p>
<p><span id="more-3930"></span></p>
<p><figure style="width: 203px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" class="size-medium" src="https://imgs.xkcd.com/comics/1_to_10.png" width="203" height="309" /><figcaption class="wp-caption-text">XKCD 953: 1 to 10</figcaption></figure></p>
<p><a href="https://en.wikipedia.org/wiki/Binary_number">Binary</a> is the type of numbering system that is native to computers. It is base-2. Numbers that normal people work with are called decimal or base-10.</p>
<p>For normal base-10 numbers you use the digits 0 through 9 to describe a number. Here’s how you would count out 10 things:</p>
<pre>1
2
3
4
5
6
7
8
9</pre>
<p>And now you’ve run out out digits. So you put a “1” in the tens place and a “0” in the ones place to get:</p>
<pre>10</pre>
<p>To try counting the same quantity in binary your first realization should be that you only have two digits (base-2) to work with: 0 and 1. So the counting would look like this:</p>
<pre>1</pre>
<p>And now you’ve immediately run out of digits. So you put a “1” in the twos place and a “0” in the ones place and start counting again:</p>
<pre>10
11</pre>
<p>And you’ve run out of digits again. This happens a lot with binary, which is why it’s not a great numbering system for people. Just continue the pattern to keep counting:</p>
<pre>100
101
110
111

1000
1001
1010</pre>
<p>We’ll stop here since we have now counted up to “10” in decimal.</p>
<p>Another way you can parse this number is to think of how each position represents a component of the number.</p>
<p>With binary 1010 the components are as follows:</p>
<pre>1 * 2<sup>3</sup> = 8
0 * 2<sup>2</sup> = 0
1 * 2<sup>1</sup> = 2
0 * 2<sup>0</sup> = 0</pre>
<p>Adding 8 + 2 gets you to 10 decimal.</p>
<p>You’ve probably heard the term “8-bit” so what is an 8-bit number? Because bits are either 0 or 1 they are represented as binary. So an 8-bit binary number with all values set to one is this:</p>
<pre>11111111</pre>
<p>That is the largest number you can fit into 8 bits. And converted to decimal it is:</p>
<p>1 * 2^7 + 1 * 2^6 + 1 * 2^5 + 1 * 2^4 + 1 * 2^3 + 1 * 2^2 + 1 * 2^1 + 1 * 2^0</p>
<p>That breaks down to:</p>
<p>128 + 64 + 32 + 16 + 8 + 4 + 2 + 1</p>
<p>Which sums to 255, a number I’m sure you’ve seen around before. It is the maximum value you get with the <a href="http://developer.xojo.com/integer-size-specific">UInt8</a> data type in Xojo.</p>
<p>Conversely, you can convert a decimal number to binary by repeatedly dividing it by 2 and noting the remainder. When the remainder is even you write a 0, when it is odd you write a 1. And then you read the number from the bottom up.</p>
<p>So to convert decimal 10 to binary:</p>
<p>10 / 2 = 5, with a remainder of 0. 0 is even so write a “0”:</p>
<pre>0</pre>
<p>Now divide 5 / 2 to get 2 with a remainder of 1, which is odd:</p>
<pre>0
1</pre>
<p>Now divide 2 /2 to get 1, with a remainder of 0:</p>
<pre>0
1
0</pre>
<p>Lastly, divide 1 / 2 to get 0 with a remainder of 1 which is odd. So you end up with this:</p>
<pre>0
1
0
1</pre>
<p>Reading that from the bottom up gives you: 1010</p>
<p>I hope you now consider yourself part of the group that understands binary!</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
