<?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>programming Archives - NeuralLantern.com</title>
	<atom:link href="https://www.NeuralLantern.com/tag/programming/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.NeuralLantern.com/tag/programming/</link>
	<description></description>
	<lastBuildDate>Mon, 06 Jul 2026 10:05:09 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.1.2</generator>

<image>
	<url>https://www.NeuralLantern.com/wp-content/uploads/2025/04/cropped-2025-04-04-Lantern-03-32x32.png</url>
	<title>programming Archives - NeuralLantern.com</title>
	<link>https://www.NeuralLantern.com/tag/programming/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>4 Graph Types: Undirected vs Directed, Weighted vs Unweighted</title>
		<link>https://www.NeuralLantern.com/4-graph-types-undirected-vs-directed-weighted-vs-unweighted/</link>
					<comments>https://www.NeuralLantern.com/4-graph-types-undirected-vs-directed-weighted-vs-unweighted/#respond</comments>
		
		<dc:creator><![CDATA[mike]]></dc:creator>
		<pubDate>Mon, 06 Jul 2026 10:05:07 +0000</pubDate>
				<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Data Structures]]></category>
		<category><![CDATA[Graphs]]></category>
		<category><![CDATA[Videos]]></category>
		<category><![CDATA[algorithms]]></category>
		<category><![CDATA[binary search tree]]></category>
		<category><![CDATA[coding tutorial]]></category>
		<category><![CDATA[computer science]]></category>
		<category><![CDATA[data structures]]></category>
		<category><![CDATA[directed graph]]></category>
		<category><![CDATA[edges]]></category>
		<category><![CDATA[graph theory]]></category>
		<category><![CDATA[graph types]]></category>
		<category><![CDATA[graphs]]></category>
		<category><![CDATA[network topology]]></category>
		<category><![CDATA[nodes]]></category>
		<category><![CDATA[pathfinding]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[undirected graph]]></category>
		<category><![CDATA[unweighted graph]]></category>
		<category><![CDATA[vertices]]></category>
		<category><![CDATA[weighted graph]]></category>
		<guid isPermaLink="false">https://www.NeuralLantern.com/?p=407</guid>

					<description><![CDATA[<p>A graph is basically a collection of nodes, also known as vertices, and edges, which are the lines that connect nodes to each other. The four types of graphs are undirected unweighted, undirected weighted, directed unweighted, and directed weighted. Graphs help represent relationships between things like computers in a network or cities and airports.</p>
<p>The post <a href="https://www.NeuralLantern.com/4-graph-types-undirected-vs-directed-weighted-vs-unweighted/">4 Graph Types: Undirected vs Directed, Weighted vs Unweighted</a> appeared first on <a href="https://www.NeuralLantern.com">NeuralLantern.com</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<figure class="wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
<iframe title="4 Graph Types: Undirected vs Directed, Weighted vs Unweighted" width="1380" height="776" src="https://www.youtube.com/embed/8Ml20VhpdrI?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
</div></figure>



<p class="wp-block-paragraph">In this video we break down the four main types of graphs used in computer science: undirected unweighted, undirected weighted, directed unweighted, and directed weighted.</p>



<p class="wp-block-paragraph">We start with the basic idea of graphs &#8211; collections of nodes (vertices) and edges &#8211; and then explore each type with clear examples. Learn how these graphs represent real-world relationships like computer networks, airport routes, road maps, and game maps.</p>



<p class="wp-block-paragraph">Perfect for anyone learning data structures, algorithms, or preparing for coding interviews.</p>



<p class="wp-block-paragraph">00:00 Introduction to Graphs<br>00:19 Basic Graph Definition<br>00:48 Nodes and Vertices<br>01:01 Empty Graph Example<br>01:17 Graph Implementation Concepts<br>02:02 Node Data and Templates<br>03:22 Adding Nodes<br>04:00 Adding Edges<br>04:44 What Graphs Represent<br>05:36 Graph Use Cases<br>06:56 Real-World Examples<br>08:35 Four Types of Graphs<br>08:52 Undirected Unweighted Graph<br>10:40 Unweighted as Unit Weights<br>11:40 Undirected Weighted Graph<br>13:32 Weighted Graph Benefits<br>15:52 Directed Weighted Graph<br>19:50 Directed Unweighted Graph<br>20:32 Summary of Four Graph Types<br>21:19 Closing and Future Videos</p>



<p class="wp-block-paragraph">=-=-=-=-=-=-=-=-=</p>



<p class="wp-block-paragraph">Thanks for watching!</p>



<p class="wp-block-paragraph">Find us on other social media here:</p>



<ul class="wp-block-list">
<li>https://www.NeuralLantern.com/social</li>



<li>Twitter / X: https://x.com/NeuralLantern</li>



<li>Rumble: https://rumble.com/c/c-3696939</li>



<li>BitChute: https://www.bitchute.com/channel/pg1Pvv5dN4Gt</li>



<li>Daily Motion: https://www.dailymotion.com/neurallantern</li>



<li>Minds: https://www.minds.com/neurallantern/</li>



<li>Odysee: https://odysee.com/@NeuralLantern:5</li>
</ul>



<p class="wp-block-paragraph">Please show your support!</p>



<ul class="wp-block-list">
<li>Buy me a coffee: https://ko-fi.com/neurallantern</li>



<li>Subscribe + Sharing on Social Media</li>



<li>Leave a comment or suggestion</li>



<li>Subscribe to the Blog: https://www.NeuralLantern.com</li>



<li>Watch the main &#8220;pinned&#8221; video of this channel for offers and extras</li>
</ul>



<p class="wp-block-paragraph">Hello there! Let&#8217;s talk about four different types of graphs that you can use and how they relate to computer science.</p>



<p class="wp-block-paragraph">Okay, so you can see like I&#8217;ve got like a blank little graph paper up here.</p>



<p class="wp-block-paragraph">I&#8217;m going to talk about graphs and just the very basic idea of graphs in general</p>



<p class="wp-block-paragraph">and then show you the four different types of graphs that we have.</p>



<p class="wp-block-paragraph">about how to implement graphs inside the machine, time complexities, maybe graph algorithms,</p>



<p class="wp-block-paragraph">and a whole bunch of stuff, terminology, everything. Okay, so the first thing is, I guess I&#8217;m going to</p>



<p class="wp-block-paragraph">assume probably most of you have sort of seen a graph before and you kind of understand a little</p>



<p class="wp-block-paragraph">bit about it already, but I&#8217;ll say that a graph is basically a collection of nodes, also known as</p>



<p class="wp-block-paragraph">vertices or vertexes, and edges, which are the lines that connect nodes to each other. This screen</p>



<p class="wp-block-paragraph">See, this is a valid graph.</p>



<p class="wp-block-paragraph">I&#8217;m not talking about the graphing paper.</p>



<p class="wp-block-paragraph">It&#8217;s just an empty graph.</p>



<p class="wp-block-paragraph">There&#8217;s nothing there.</p>



<p class="wp-block-paragraph">So it&#8217;s still valid.</p>



<p class="wp-block-paragraph">It&#8217;s just blank.</p>



<p class="wp-block-paragraph">Okay, so then what I want to do is start drawing some nodes.</p>



<p class="wp-block-paragraph">What are the nodes again?</p>



<p class="wp-block-paragraph">Those are just vertices.</p>



<p class="wp-block-paragraph">Those are just like little data structure objects you can imagine in the code.</p>



<p class="wp-block-paragraph">I don&#8217;t want to get too far ahead of myself, but imagine that you have a class called graph.</p>



<p class="wp-block-paragraph">This is just one way to imagine.</p>



<p class="wp-block-paragraph">We have a class called graph and then a nested class inside of a graph called a node or a vertex</p>



<p class="wp-block-paragraph">If you want to be more fancy</p>



<p class="wp-block-paragraph">So the vertex class itself by the way</p>



<p class="wp-block-paragraph">This is not always going to be the way that you actually do this in your code the other representations that we&#8217;ll talk about sooner a little bit easier, but</p>



<p class="wp-block-paragraph">The vertex class itself needs to basically hold some data</p>



<p class="wp-block-paragraph">Depending on your implementation it might know about who it&#8217;s connected to maybe the graph knows that instead</p>



<p class="wp-block-paragraph">instead. In my implementations, the graph is going to know everything, but the vertex or the node</p>



<p class="wp-block-paragraph">itself needs to hold one piece of data. That&#8217;s kind of the whole point. So I&#8217;m going to say that</p>



<p class="wp-block-paragraph">the data type that these nodes hold are just integers. So I&#8217;m just going to put like a six in</p>



<p class="wp-block-paragraph">here just to indicate we have one node and the templated data type that it holds is an integer.</p>



<p class="wp-block-paragraph">And the specific integer for this specific node is just the number six. You can have any template</p>



<p class="wp-block-paragraph">any template type if you really want to you can people put floats in there you could put a custom</p>



<p class="wp-block-paragraph">custom class in there whatever you want but i just want to show you that we have a class called</p>



<p class="wp-block-paragraph">vertex or node and inside of it&#8217;s got a template type maybe just to make this a little bit more</p>



<p class="wp-block-paragraph">clear i&#8217;ll say you can imagine inside the vertex class uh there is a template type and we&#8217;ll call</p>



<p class="wp-block-paragraph">it uh i don&#8217;t know node node value type or something and we&#8217;ll call it data and then up</p>



<p class="wp-block-paragraph">I&#8217;m doing C++ up here.</p>



<p class="wp-block-paragraph">We have to kind of define the whole graph class as a template class.</p>



<p class="wp-block-paragraph">Now, of course, you could define the vertex class as the template class,</p>



<p class="wp-block-paragraph">but if you define the graph class as a template, then it all kind of falls through.</p>



<p class="wp-block-paragraph">So I&#8217;m just going to say class node value type.</p>



<p class="wp-block-paragraph">And so if you&#8217;ve written template classes before in C++,</p>



<p class="wp-block-paragraph">now you know that the user can instance the graph and at the same time,</p>



<p class="wp-block-paragraph">specify what is the data type of the stuff that the nodes hold.</p>



<p class="wp-block-paragraph">the stuff that the nodes hold.</p>



<p class="wp-block-paragraph">We do the same thing for edges too,</p>



<p class="wp-block-paragraph">but notice how there are no nodes that are connected to each other.</p>



<p class="wp-block-paragraph">So we have no edges in this graph.</p>



<p class="wp-block-paragraph">This is still a valid graph,</p>



<p class="wp-block-paragraph">but we could just sort of copy a node just for fun and say,</p>



<p class="wp-block-paragraph">all right, we&#8217;ve got two nodes now, two vertices.</p>



<p class="wp-block-paragraph">They could have the same value if you want.</p>



<p class="wp-block-paragraph">Graphs are supposed to, you know, support duplicate values in the nodes,</p>



<p class="wp-block-paragraph">but I&#8217;m just going to change the value here.</p>



<p class="wp-block-paragraph">This is also a valid graph.</p>



<p class="wp-block-paragraph">You don&#8217;t really need edges to have a valid graph.</p>



<p class="wp-block-paragraph">edges to have a valid graph. This is just something called a something called a graph that is not</p>



<p class="wp-block-paragraph">connected. We&#8217;ll talk about all that terminology and how to detect it in a future video. For now,</p>



<p class="wp-block-paragraph">I&#8217;m just going to say we have like a little graph here, which is kind of boring, but I&#8217;m going to</p>



<p class="wp-block-paragraph">add an edge. An edge is basically just, you know, a little mini data structure that connects two</p>



<p class="wp-block-paragraph">nodes. Depending on the way you represent this in the machine, which we&#8217;ll talk about in future</p>



<p class="wp-block-paragraph">well, a whole bunch of different ways.</p>



<p class="wp-block-paragraph">You could imagine this as a full-fledged class,</p>



<p class="wp-block-paragraph">although that&#8217;s not always going to be the way that we represent an actual edge.</p>



<p class="wp-block-paragraph">So imagine that we have a nested class called edge.</p>



<p class="wp-block-paragraph">And inside the edge class, we&#8217;ve got, you know, some stuff.</p>



<p class="wp-block-paragraph">We could have a weight, which means the cost of traveling against the edge.</p>



<p class="wp-block-paragraph">We could have many other properties.</p>



<p class="wp-block-paragraph">For now, I&#8217;ll just try to keep it simple.</p>



<p class="wp-block-paragraph">is pretty much a collection of vertices and edges and some sort of connection.</p>



<p class="wp-block-paragraph">What is a graph really for?</p>



<p class="wp-block-paragraph">Some people at first think that a graph is another way to represent a database.</p>



<p class="wp-block-paragraph">I&#8217;m going to erase this thing over here.</p>



<p class="wp-block-paragraph">Graphs, you could sort of use them as databases,</p>



<p class="wp-block-paragraph">but they&#8217;re not very good as databases because</p>



<p class="wp-block-paragraph">it would be really, really slow to search through the graph</p>



<p class="wp-block-paragraph">to find some piece of data that you&#8217;re looking for.</p>



<p class="wp-block-paragraph">It could be like a linear time database.</p>



<p class="wp-block-paragraph">better would be to take this graph and add a bunch of rules as you probably have found</p>



<p class="wp-block-paragraph">in my other videos by now and turn it into a binary search tree.</p>



<p class="wp-block-paragraph">A binary search tree is lightning fast.</p>



<p class="wp-block-paragraph">It runs in log time.</p>



<p class="wp-block-paragraph">Hash tables are faster than binary search trees, but basically a graph is always going</p>



<p class="wp-block-paragraph">to be way slower than a binary search tree unless the binary search tree is severely</p>



<p class="wp-block-paragraph">imbalanced.</p>



<p class="wp-block-paragraph">But that&#8217;s something for another video.</p>



<p class="wp-block-paragraph">Anyway, so we have a graph and it&#8217;s not a good database.</p>



<p class="wp-block-paragraph">What would a graph be good for?</p>



<p class="wp-block-paragraph">would a graph be good for? Well, graphs are usually pretty good to help you represent</p>



<p class="wp-block-paragraph">relationships between things. For example, the six and the one, imagine the six is something,</p>



<p class="wp-block-paragraph">maybe it&#8217;s a computer, maybe it&#8217;s a city, maybe it&#8217;s, I don&#8217;t know, like a train station,</p>



<p class="wp-block-paragraph">and the edges could represent connections. So I&#8217;m just going to start changing these values</p>



<p class="wp-block-paragraph">have some nodes just kind of hanging out off to the side, not really connected to anything.</p>



<p class="wp-block-paragraph">Maybe not great for your particular use case, but like it&#8217;s a valid graph. So I&#8217;m just going to,</p>



<p class="wp-block-paragraph">I&#8217;m just going to connect this and try to make this into a better graph.</p>



<p class="wp-block-paragraph">That&#8217;s a little bit more interesting. So we&#8217;ve got graphs that do a whole bunch of different</p>



<p class="wp-block-paragraph">things. Let me change these values real fast. I&#8217;ll maybe turn that into a 13 and turn that</p>



<p class="wp-block-paragraph">So imagine that we have like a little connection here, a little connection here, maybe another</p>



<p class="wp-block-paragraph">connection here and another one there.</p>



<p class="wp-block-paragraph">And you know, you are allowed to have connections that sort of look weird, like going from this</p>



<p class="wp-block-paragraph">six all the way around to this 13.</p>



<p class="wp-block-paragraph">That&#8217;s totally valid also.</p>



<p class="wp-block-paragraph">So I&#8217;ve basically just drawn a random graph, random nodes and random edges.</p>



<p class="wp-block-paragraph">Imagine that every single node here is a computer in a computer network and imagine every edge</p>



<p class="wp-block-paragraph">every edge which connects the nodes is just some sort of a connection let&#8217;s say a network cable</p>



<p class="wp-block-paragraph">or a wi-fi signal or something like that so if you imagine it that way then this graph could</p>



<p class="wp-block-paragraph">represent a network topology a bunch of computers connected together if these were cities and this</p>



<p class="wp-block-paragraph">is like actually maybe these are airports in cities you could imagine a graph could represent</p>



<p class="wp-block-paragraph">the relationship between different airports in which planes will fly notice on this graph just</p>



<p class="wp-block-paragraph">that the uh you know the uh the city number one uh there are no flights connecting it directly to</p>



<p class="wp-block-paragraph">city 44 but you could probably imagine well if we take a flight to uh from city one to city 10 and</p>



<p class="wp-block-paragraph">then from city 10 to 44 then we can get from one to 44 we just have to be clever about our connecting</p>



<p class="wp-block-paragraph">flights um let&#8217;s see so we could do like road maps airport maps the worldwide web is basically a graph</p>



<p class="wp-block-paragraph">at least from a certain perspective electrical circuits that are connected to each other</p>



<p class="wp-block-paragraph">are connected to each other even game maps what if your character is allowed to stand here in</p>



<p class="wp-block-paragraph">in space number three on some map and the character is only allowed to travel to space 13 or</p>



<p class="wp-block-paragraph">space 6 but not directly to space 1 well it could be a map that helps you understand where your</p>



<p class="wp-block-paragraph">character can go in a game okay so that&#8217;s like the basic idea of of what a graph is and uh how it</p>



<p class="wp-block-paragraph">actual four types of graphs that I&#8217;m going to go over in more detail in future videos. Let&#8217;s see,</p>



<p class="wp-block-paragraph">what time is it right now? We got like 10 minutes. Okay, so I can still kind of make this fast.</p>



<p class="wp-block-paragraph">So the first type of graph that we&#8217;re looking at right now is actually something called an</p>



<p class="wp-block-paragraph">undirected, unweighted graph. Why is it, let&#8217;s see, let me write this down first. It&#8217;s an undirected,</p>



<p class="wp-block-paragraph">undirected, unweighted graph. So why is this undirected? Because the edges don&#8217;t have direction.</p>



<p class="wp-block-paragraph">If I was standing in, you know, city six and I wanted to like drive or fly or whatever</p>



<p class="wp-block-paragraph">from city six to city three, then I should be able to do it because this edge that connects</p>



<p class="wp-block-paragraph">them doesn&#8217;t really say that I have to go in one direction or the other. I could also go to city</p>



<p class="wp-block-paragraph">three and then just walk right back or fly right back to city six. There&#8217;s no direction. So there&#8217;s</p>



<p class="wp-block-paragraph">no direction. So there&#8217;s an this that&#8217;s that&#8217;s why this is an undirected graph. This is an</p>



<p class="wp-block-paragraph">unweighted graph because we haven&#8217;t specified a cost for traveling along an edge. For example,</p>



<p class="wp-block-paragraph">if you know, if you&#8217;re at city three here, and you want to fly to city 13, how much jet fuel</p>



<p class="wp-block-paragraph">does it cost? How much time does it cost? If three is a computer and 13 is a computer,</p>



<p class="wp-block-paragraph">and the edges like a network cable, like how much money does it cost to transmit the data?</p>



<p class="wp-block-paragraph">transmit the data or what is the lag in milliseconds.</p>



<p class="wp-block-paragraph">You know, you can represent all sorts of things with these edges,</p>



<p class="wp-block-paragraph">but there&#8217;s no value on these edges,</p>



<p class="wp-block-paragraph">which means there are no weights to these edges.</p>



<p class="wp-block-paragraph">So that&#8217;s why this is an undirected and also unweighted graph.</p>



<p class="wp-block-paragraph">Uh, the first upgrade that I want to do is just kind of show you what you can</p>



<p class="wp-block-paragraph">sort of assume about an unweighted graph. This is not always true.</p>



<p class="wp-block-paragraph">It just depends on who you talk to and what your application implementations are.</p>



<p class="wp-block-paragraph">So imagine the node that goes from six, sorry, the edge that goes from six to one.</p>



<p class="wp-block-paragraph">If it&#8217;s an unweighted graph, you could just probably imagine that every weight is just a one.</p>



<p class="wp-block-paragraph">The point being that it always costs the same amount to travel along every edge,</p>



<p class="wp-block-paragraph">because in an unweighted graph, we don&#8217;t differentiate between the different edges</p>



<p class="wp-block-paragraph">in terms of their costs.</p>



<p class="wp-block-paragraph">We could just put a bunch of ones on all these edges.</p>



<p class="wp-block-paragraph">And it would still, you know, basically be considered an unweighted graph.</p>



<p class="wp-block-paragraph">It depends on who you talk to.</p>



<p class="wp-block-paragraph">maybe all the weights are zero, maybe all the weights are 10 or whatever.</p>



<p class="wp-block-paragraph">But, you know, usually I put a one there because I&#8217;d like to imagine the cost could just be the number of hops.</p>



<p class="wp-block-paragraph">So, for example, if I wanted to go from city six to city 10,</p>



<p class="wp-block-paragraph">I could probably, you know, start at city six and then go to city one and then hop to city 10.</p>



<p class="wp-block-paragraph">How many actual hops did I do? I did two.</p>



<p class="wp-block-paragraph">I could also come up with that number by just looking at the sum of all the weights of all the edges.</p>



<p class="wp-block-paragraph">all the edges. So notice how when I go from six to one, that costs me one weight or one hop. And</p>



<p class="wp-block-paragraph">then when I go from one to 10, that&#8217;s another one. So if you put ones on all the edges in an</p>



<p class="wp-block-paragraph">unweighted graph, then you&#8217;re kind of saying the total cost of some path is really just the number</p>



<p class="wp-block-paragraph">of hops. So it&#8217;s up to you. Anyway, that&#8217;s unweighted and undirected. Let&#8217;s upgrade this</p>



<p class="wp-block-paragraph">see we have an undirected and unweighted and i&#8217;m just going to duplicate this real fast and change</p>



<p class="wp-block-paragraph">this to a weighted graph so undirected but also weighted and the thing is as soon as you start</p>



<p class="wp-block-paragraph">putting numbers on a graph on the edges of a graph well then it&#8217;s considered weighted so even even a</p>



<p class="wp-block-paragraph">graph that has all ones on all the edges you could also call that weighted but now you have the</p>



<p class="wp-block-paragraph">freedom since it is considered a weighted graph to just assign different values to all the edges</p>



<p class="wp-block-paragraph">to all the edges. Again, these edges are a class sometimes, or you can think of them that way</p>



<p class="wp-block-paragraph">inside the graph. And the edge weights themselves are definitely considered a T type, a templated</p>



<p class="wp-block-paragraph">type, which means, you know, right now I&#8217;m clearly typing integers, but you could type some other</p>



<p class="wp-block-paragraph">data type. You could type floats. You could type some weird data type, like a string.</p>



<p class="wp-block-paragraph">Whether or not that&#8217;s going to be useful depends on your program, you know, what you&#8217;re trying to</p>



<p class="wp-block-paragraph">you know, what you&#8217;re trying to do with the graph. But let&#8217;s see, I think I&#8217;ve added custom numbers</p>



<p class="wp-block-paragraph">to every single edge. So now this is definitely an undirected, but weighted graph. That&#8217;s the</p>



<p class="wp-block-paragraph">second type of graph that we&#8217;re talking about. Okay, what&#8217;s what&#8217;s cool about a weighted graph?</p>



<p class="wp-block-paragraph">Well, imagine again, that this is an airport map, where we&#8217;re representing relationships between,</p>



<p class="wp-block-paragraph">you know, cities, like where can we fly and stuff. We&#8217;re basically saying at this point,</p>



<p class="wp-block-paragraph">it&#8217;s going to cost you 44 of something.</p>



<p class="wp-block-paragraph">Maybe this is a graph representing jet fuel or time or frequent flyer points or something like that.</p>



<p class="wp-block-paragraph">If you consider your edges to be custom classes,</p>



<p class="wp-block-paragraph">you could even put a whole bunch of different types of values in your graph at the same time</p>



<p class="wp-block-paragraph">to make it a little bit more flexible.</p>



<p class="wp-block-paragraph">But for now, we&#8217;ll just say there&#8217;s one templated type,</p>



<p class="wp-block-paragraph">which means if we go back up to this code real fast, where was that code at?</p>



<p class="wp-block-paragraph">Where was that code at?</p>



<p class="wp-block-paragraph">And we had, you know, our rough idea of, you know, what the, what the graph holds, you</p>



<p class="wp-block-paragraph">know, it holds like vertices and edges.</p>



<p class="wp-block-paragraph">We could upgrade this just a little bit to say that there is a, an edge value type.</p>



<p class="wp-block-paragraph">So I&#8217;m going to say class edge value, edge weight type, something like that.</p>



<p class="wp-block-paragraph">for the edge so that I can save characters. And then here, I&#8217;ll change this to a type for the</p>



<p class="wp-block-paragraph">node. This is why we call it T type. There&#8217;s like, we put the keyword template here in C++.</p>



<p class="wp-block-paragraph">And then sometimes people just use T&#8217;s here for these tokens. So I&#8217;m just going to say</p>



<p class="wp-block-paragraph">the type of data that a node can hold is going to be the T node. And then the type of data that</p>



<p class="wp-block-paragraph">the edge could hold would be the T edge. We&#8217;ll call that data. Or we could call that weight,</p>



<p class="wp-block-paragraph">because usually that data comes into play when you&#8217;re traveling along an edge, right? So there&#8217;s</p>



<p class="wp-block-paragraph">traveling along an edge, right? So there&#8217;s like two different types here. Anyway, so we got an</p>



<p class="wp-block-paragraph">undirected and unweighted graph. If we traveled from city six to city one, that costs us 44. But</p>



<p class="wp-block-paragraph">if you look at the graph a little bit more closely, we could take the longer way around. We could say</p>



<p class="wp-block-paragraph">go from six to three, and then go from three to 13. And then actually, let me change the color</p>



<p class="wp-block-paragraph">to orange so that you can see there&#8217;s different paths, six to three, and then three to 13,</p>



<p class="wp-block-paragraph">and then 13 to one, even though we took more hops,</p>



<p class="wp-block-paragraph">and that might have been considered more expensive</p>



<p class="wp-block-paragraph">in an unweighted graph,</p>



<p class="wp-block-paragraph">you can see that the cost of the first path</p>



<p class="wp-block-paragraph">from six to one, that&#8217;s 44.</p>



<p class="wp-block-paragraph">And the cost of the second path is seven plus three,</p>



<p class="wp-block-paragraph">that&#8217;s 10, and then plus nine, so that&#8217;s 19.</p>



<p class="wp-block-paragraph">So if we take the long way,</p>



<p class="wp-block-paragraph">it actually costs us less</p>



<p class="wp-block-paragraph">of whatever we&#8217;ve determined this unit is.</p>



<p class="wp-block-paragraph">You know, less jet fuel, less time, less whatever.</p>



<p class="wp-block-paragraph">less whatever these graphs in the machine are not necessarily going to be to scale because the</p>



<p class="wp-block-paragraph">machine in your computer your computer doesn&#8217;t really keep track of like the physical positioning</p>



<p class="wp-block-paragraph">of all these nodes and edges it just can keeps track of the relationship between the nodes and</p>



<p class="wp-block-paragraph">the edges and the weights and all that stuff so two different paths that we could take to get</p>



<p class="wp-block-paragraph">from six to one one of the paths is less expensive um or less time costly or just whatever and a graph</p>



<p class="wp-block-paragraph">data structure can kind of help us figure that out if we&#8217;re using an algorithm that understands</p>



<p class="wp-block-paragraph">weights okay so undirected and unweighted let&#8217;s add direction so um i&#8217;m going to erase this stuff</p>



<p class="wp-block-paragraph">right here real quick and in an undirected graph remember you can just kind of go in either</p>



<p class="wp-block-paragraph">direction along any edge but in a directed graph every single edge needs to have a direction so as</p>



<p class="wp-block-paragraph">I change one of the edges to have direction, then I must change all of the edges to have direction</p>



<p class="wp-block-paragraph">as well. So I&#8217;m just saying, okay, as soon as I did that, now this is an invalid graph</p>



<p class="wp-block-paragraph">because some of the edges don&#8217;t have direction. So now I need to fix everything. So I just,</p>



<p class="wp-block-paragraph">I&#8217;m going to arbitrarily and randomly choose a direction for every single edge like this.</p>



<p class="wp-block-paragraph">And then as soon as I&#8217;m done, I&#8217;m going to deal, I guess, with that giant edge</p>



<p class="wp-block-paragraph">that giant edge. So I&#8217;m going to go like that. So let&#8217;s see, all the edges seem to have direction.</p>



<p class="wp-block-paragraph">Now I&#8217;m just going to hand draw an arrow on one side of this giant edge. Okay. So this is directed</p>



<p class="wp-block-paragraph">and also weighted. What can we do with the directed graph? Well, it just basically tells</p>



<p class="wp-block-paragraph">you which direction you&#8217;re allowed to travel in. What if you have an airport where city six can</p>



<p class="wp-block-paragraph">only fly to city one, but city one, for some reason, never flies to city six. You got to take</p>



<p class="wp-block-paragraph">take like the long way you got to go from city one to 13 to three to six that&#8217;s something that</p>



<p class="wp-block-paragraph">a graph could help you represent what if your character in your game can only go in one direction</p>



<p class="wp-block-paragraph">but not the other direction okay no problem i mean that&#8217;s pretty much it you&#8217;re only allowed</p>



<p class="wp-block-paragraph">to travel in the same direction as the edge points but now we have a graph that is a lot less</p>



<p class="wp-block-paragraph">flexible because for example before we used to be able to go from city uh 10 to city 44 and then</p>



<p class="wp-block-paragraph">then come back again later if we wanted in the opposite direction. We can no longer do that</p>



<p class="wp-block-paragraph">because this edge only goes to 10. It doesn&#8217;t even go to 44. We can&#8217;t even ever actually get to 44.</p>



<p class="wp-block-paragraph">How do you sort of solve that? Well, just add another edge in the opposite direction.</p>



<p class="wp-block-paragraph">In graphs, you are allowed to do something called a parallel edge,</p>



<p class="wp-block-paragraph">which just basically means, you know, two edges between the same pair of nodes that just point</p>



<p class="wp-block-paragraph">in the same direction. You&#8217;re also allowed to do, you know, opposite facing edges. So</p>



<p class="wp-block-paragraph">edges so i just added a second edge there going from 10 to 44 and now if i was you know hanging</p>



<p class="wp-block-paragraph">out in city 10 i could just go back and forth between city 10 and 44 as much as i wanted to</p>



<p class="wp-block-paragraph">oh i forgot to add an edge weight for that new edge which means i wrote down an invalid graph</p>



<p class="wp-block-paragraph">so i&#8217;m just going to say two so uh maybe the wind is blowing in in your favor when you&#8217;re going from</p>



<p class="wp-block-paragraph">city 10 to city 44 maybe it&#8217;s blowing against you if you&#8217;re talking about city 44 to city 10 you</p>



<p class="wp-block-paragraph">you know whatever but you just have to have edge uh edge weight on every single edge</p>



<p class="wp-block-paragraph">okay so uh that&#8217;s directed and also weighted um and you can probably imagine previously when we</p>



<p class="wp-block-paragraph">had an undirected um graph when there was just like you know one edge going between uh two nodes</p>



<p class="wp-block-paragraph">and there was no direction on it like you know 44 to 10 if we just had like one edge with no</p>



<p class="wp-block-paragraph">have two edges each going in the opposite direction so we have directed and weighted i think the last</p>



<p class="wp-block-paragraph">thing that we didn&#8217;t do was directed and unweighted right so we have let me just double check real</p>



<p class="wp-block-paragraph">fast here we have undirected and unweighted and then we had undirected and weighted and then</p>



<p class="wp-block-paragraph">directed and weighted okay so now let&#8217;s do um i&#8217;m getting lost already oh my gosh i can&#8217;t believe i</p>



<p class="wp-block-paragraph">I saw undirected and unweighted so we did undirected twice already undirected so we&#8217;re</p>



<p class="wp-block-paragraph">going to do directed and unweighted next okay so the next graph a little bit less useful than</p>



<p class="wp-block-paragraph">what we&#8217;re looking at this this type of graph is a little bit more useful we&#8217;re going to do</p>



<p class="wp-block-paragraph">directed and unweighted oh my god okay directed and unweighted so directed and unweighted you</p>



<p class="wp-block-paragraph">Directed and unweighted, you can imagine, just means we get rid of all these weights.</p>



<p class="wp-block-paragraph">And then we keep the direction on all the edges.</p>



<p class="wp-block-paragraph">So this means we can keep track of where we&#8217;re allowed to go, if we&#8217;re pathfinding or just whatever.</p>



<p class="wp-block-paragraph">But we don&#8217;t really know what it costs to travel between the different graphs.</p>



<p class="wp-block-paragraph">So that&#8217;s directed and unweighted.</p>



<p class="wp-block-paragraph">Let&#8217;s see here.</p>



<p class="wp-block-paragraph">I&#8217;m going to just duplicate this or just make a new blank slide.</p>



<p class="wp-block-paragraph">Okay, undirected, oh gosh, I&#8217;ve got pink letters.</p>



<p class="wp-block-paragraph">Let&#8217;s see, undirected plus unweighted.</p>



<p class="wp-block-paragraph">And we&#8217;ve got undirected plus weighted.</p>



<p class="wp-block-paragraph">And then we&#8217;ve got directed plus unweighted.</p>



<p class="wp-block-paragraph">I don&#8217;t think I&#8217;m writing these down in the same order,</p>



<p class="wp-block-paragraph">but that&#8217;s okay.</p>



<p class="wp-block-paragraph">And then we&#8217;ve got directed plus weighted.</p>



<p class="wp-block-paragraph">So basically, you know, four types of graphs</p>



<p class="wp-block-paragraph">that we can talk about.</p>



<p class="wp-block-paragraph">In future videos, we&#8217;re going to go over graphs</p>



<p class="wp-block-paragraph">in more detail.</p>



<p class="wp-block-paragraph">We&#8217;ll talk about graph terminology,</p>



<p class="wp-block-paragraph">maybe some pathfinding algorithms.</p>



<p class="wp-block-paragraph">And yeah, so this is just a basic intro.</p>



<p class="wp-block-paragraph">How much time do we spend already?</p>



<p class="wp-block-paragraph">Oh God, we spent so much time.</p>



<p class="wp-block-paragraph">Spent like 22 minutes.</p>



<p class="wp-block-paragraph">Dang, man, even the smallest thing takes time.</p>



<p class="wp-block-paragraph">So I&#8217;ll see you in a future video</p>



<p class="wp-block-paragraph">when we talk more and more and more about graphs</p>



<p class="wp-block-paragraph">and other data structures concepts.</p>



<p class="wp-block-paragraph">Thanks for watching this video.</p>



<p class="wp-block-paragraph">I hope you learned a little bit of stuff</p>



<p class="wp-block-paragraph">I hope you learned a little bit of stuff and had a little bit of fun.</p>



<p class="wp-block-paragraph">I&#8217;m out of here.</p>



<p class="wp-block-paragraph">Go.</p>



<p class="wp-block-paragraph">Hey, everybody.</p>



<p class="wp-block-paragraph">Thanks for watching this video again from the bottom of my heart.</p>



<p class="wp-block-paragraph">I really appreciate it.</p>



<p class="wp-block-paragraph">I do hope you did learn something and have some fun.</p>



<p class="wp-block-paragraph">If you could do me a please, a small little favor,</p>



<p class="wp-block-paragraph">could you please subscribe and follow this channel or these videos</p>



<p class="wp-block-paragraph">or whatever it is you do on the current social media website that you&#8217;re looking at right now,</p>



<p class="wp-block-paragraph">it would really mean the world to me.</p>



<p class="wp-block-paragraph">And it&#8217;ll help make more videos and grow this community.</p>



<p class="wp-block-paragraph">So we&#8217;ll be able to do more videos, longer videos, better videos,</p>



<p class="wp-block-paragraph">or just I&#8217;ll be able to keep making videos in general.</p>



<p class="wp-block-paragraph">So please do me a kindness and subscribe.</p>



<p class="wp-block-paragraph">You know, sometimes I&#8217;m sleeping in the middle of the night</p>



<p class="wp-block-paragraph">and I just wake up because I know somebody subscribed or followed.</p>



<p class="wp-block-paragraph">It just wakes me up and I get filled with joy.</p>



<p class="wp-block-paragraph">That&#8217;s exactly what happens every single time.</p>



<p class="wp-block-paragraph">So you could do it as a nice favor to me or you could you control me if you want to just wake me up in the middle</p>



<p class="wp-block-paragraph">And I just subscribe and then I&#8217;ll just wake up. I promise that&#8217;s what will happen</p>



<p class="wp-block-paragraph">Also, if you look at the middle of the screen right now</p>



<p class="wp-block-paragraph">You should see a QR code which you can scan in order to go to the website</p>



<p class="wp-block-paragraph">which I think is also named somewhere at the bottom of this video and</p>



<p class="wp-block-paragraph">It&#8217;ll take you to my main website where you can just kind of like see all the videos</p>



<p class="wp-block-paragraph">I published and the services and tutorials and things that I offer and all that good stuff and</p>



<p class="wp-block-paragraph">and if you have a suggestion for clarifications or errata or just future</p>



<p class="wp-block-paragraph">videos that you want to see please leave a comment or if you just want to say hey</p>



<p class="wp-block-paragraph">what&#8217;s up what&#8217;s going on you know just send me a comment whatever I also wake</p>



<p class="wp-block-paragraph">up for those in the middle of the night I get I wake up in a cold sweat I&#8217;m like</p>



<p class="wp-block-paragraph">it would really it really mean the world to me I would really appreciate it so</p>



<p class="wp-block-paragraph">enjoy the cool music as as I fade into the darkness which is coming for us all.</p>



<p class="wp-block-paragraph">Thank you.</p>



<p class="wp-block-paragraph">I&#8217;m going to go ahead and get started.</p>



<p class="wp-block-paragraph">Thank you.</p>



<p class="wp-block-paragraph">Hello there.</p>



<p class="wp-block-paragraph">Let&#8217;s talk about the four types of…</p>



<p class="wp-block-paragraph">Hello there.</p>
<p>The post <a href="https://www.NeuralLantern.com/4-graph-types-undirected-vs-directed-weighted-vs-unweighted/">4 Graph Types: Undirected vs Directed, Weighted vs Unweighted</a> appeared first on <a href="https://www.NeuralLantern.com">NeuralLantern.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.NeuralLantern.com/4-graph-types-undirected-vs-directed-weighted-vs-unweighted/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Mastering Standard Input, Output, and Error (STDIN, STDOUT, STDERR) in Linux with Yasm Assembly Examples</title>
		<link>https://www.NeuralLantern.com/mastering-standard-input-output-and-error-stdin-stdout-stderr-in-linux-with-yasm-assembly-examples/</link>
					<comments>https://www.NeuralLantern.com/mastering-standard-input-output-and-error-stdin-stdout-stderr-in-linux-with-yasm-assembly-examples/#respond</comments>
		
		<dc:creator><![CDATA[mike]]></dc:creator>
		<pubDate>Mon, 22 Sep 2025 11:53:48 +0000</pubDate>
				<category><![CDATA[Assembly Language]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Videos]]></category>
		<category><![CDATA[assembly programming]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[file descriptors]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Linux pipes]]></category>
		<category><![CDATA[Linux tutorial]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[standard error]]></category>
		<category><![CDATA[standard input]]></category>
		<category><![CDATA[standard output]]></category>
		<category><![CDATA[STDERR]]></category>
		<category><![CDATA[STDIN]]></category>
		<category><![CDATA[STDOUT]]></category>
		<category><![CDATA[system calls]]></category>
		<category><![CDATA[Yasm assembly]]></category>
		<guid isPermaLink="false">https://www.NeuralLantern.com/?p=230</guid>

					<description><![CDATA[<p>Explore Linux's STDIN, STDOUT, and STDERR pipes with a fun Yasm Assembly demo. Learn how programs communicate, redirect outputs, and handle inputs in this beginner-friendly guide.</p>
<p>The post <a href="https://www.NeuralLantern.com/mastering-standard-input-output-and-error-stdin-stdout-stderr-in-linux-with-yasm-assembly-examples/">Mastering Standard Input, Output, and Error (STDIN, STDOUT, STDERR) in Linux with Yasm Assembly Examples</a> appeared first on <a href="https://www.NeuralLantern.com">NeuralLantern.com</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<figure class="wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
<iframe title="Mastering Standard Input, Output, and Error (STDIN, STDOUT, STDERR) in Linux with Yasm Assembly" width="1380" height="776" src="https://www.youtube.com/embed/8Jv1_q0cyaw?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
</div></figure>



<p class="wp-block-paragraph">Get a clear, hands-on look at Linux&#8217;s standard input (STDIN), output (STDOUT), and error (STDERR) pipes! In this video, we explore how programs communicate using these essential streams, with practical examples in Yasm Assembly (no assembly knowledge needed!). Learn to redirect outputs, handle errors, and read inputs like a pro. Whether you&#8217;re a beginner or seasoned coder, this fun demo breaks down the basics of Linux pipes. Subscribe for more coding insights and check out the full tutorial on our site!</p>



<p class="wp-block-paragraph">Introduction to STDIN, STDOUT, STDERR 00:00:00<br>Overview of Pipes in Linux 00:00:07<br>Explanation of File Descriptors 00:01:12<br>Demonstrating Echo Command 00:01:24<br>Redirecting Standard Output 00:02:02<br>C++ Example with cout and cerr 00:02:48<br>Purpose of Separate Error Pipe 00:03:28<br>Assembly Program Introduction 00:04:55<br>Creating Data Section in Yasm 00:05:22<br>Writing Helper Functions 00:07:37<br>Printing to Standard Output and Error 00:11:29<br>Testing Output Redirection 00:12:43<br>Standard Input Explanation 00:14:54<br>Creating Stack Buffer for Input 00:16:03<br>Reading from Standard Input 00:17:28<br>Piping Input to Program 00:20:54<br>Handling Null Terminators 00:22:02<br>Conclusion and Call to Subscribe 00:23:53</p>



<p class="wp-block-paragraph">Thanks for watching!</p>



<p class="wp-block-paragraph">Find us on other social media here:</p>



<ul class="wp-block-list">
<li>https://www.NeuralLantern.com/social</li>
</ul>



<p class="wp-block-paragraph">Please help support us!</p>



<ul class="wp-block-list">
<li>Subscribing + Sharing on Social Media</li>



<li>Leaving a comment or suggestion</li>



<li>Subscribing to our Blog</li>



<li>Watching the main &#8220;pinned&#8221; video of this channel for offers and extras</li>
</ul>



<p class="wp-block-paragraph">Hey everybody.</p>



<p class="wp-block-paragraph">In this video I&#8217;m going to talk to you a little bit about standard input, standard output,</p>



<p class="wp-block-paragraph">and standard error.</p>



<p class="wp-block-paragraph">Three pipes that every program has in Linux that allow it to just communicate in a very</p>



<p class="wp-block-paragraph">standard way.</p>



<p class="wp-block-paragraph">I&#8217;m going to show you some example code written in Yasm Assembly, but assembly knowledge is</p>



<p class="wp-block-paragraph">not necessarily required for this video.</p>



<p class="wp-block-paragraph">You can just sort of follow along.</p>



<p class="wp-block-paragraph">Anyway, what is standard input, standard output, and standard error?</p>



<p class="wp-block-paragraph">Well for starters, every program that gets launched, under the hood, the operating system</p>



<p class="wp-block-paragraph">will typically attach three pipes to it.</p>



<p class="wp-block-paragraph">Basically one for standard input, one for standard output, and one for standard error.</p>



<p class="wp-block-paragraph">the program pretty easily. So let&#8217;s see. Oh, I know what to do. There&#8217;s an echo command, right?</p>



<p class="wp-block-paragraph">So here&#8217;s the program called echo. When the program launches, it&#8217;s going to have three pipes</p>



<p class="wp-block-paragraph">attached to it, just like I told you before. These pipes also behave as file descriptors,</p>



<p class="wp-block-paragraph">as if you had opened a file, but their file descriptor numbers are always zero and one and two.</p>



<p class="wp-block-paragraph">Zero for standard input, one for standard output, and two for standard error. So if I launch the</p>



<p class="wp-block-paragraph">program it&#8217;s going to get those three pipes those three file descriptors and</p>



<p class="wp-block-paragraph">right away the standard output is going to get attached to the program running</p>



<p class="wp-block-paragraph">our terminal here well not necessarily the actual terminal but bash under the</p>



<p class="wp-block-paragraph">hood which is the program that we&#8217;re using to interact with the operating</p>



<p class="wp-block-paragraph">system so basically the program launches and based on this incoming argument that</p>



<p class="wp-block-paragraph">I give it hello then it&#8217;s going to print the string hello right but what it&#8217;s</p>



<p class="wp-block-paragraph">its standard output pipe its standard output file descriptor I can test this</p>



<p class="wp-block-paragraph">for sure by just sort of doing the command again and then muting its</p>



<p class="wp-block-paragraph">standard output pipe with this little shell trick I&#8217;ll do a arrow or a greater</p>



<p class="wp-block-paragraph">than angle bracket and I&#8217;ll just send the first pipe I&#8217;ll do one I&#8217;ll send it</p>



<p class="wp-block-paragraph">to dev null and on Linux dev null is just if you send anything there it just</p>



<p class="wp-block-paragraph">it&#8217;s just totally ignored so if i send uh the pipe labeled number one to just nowhere then notice how</p>



<p class="wp-block-paragraph">it doesn&#8217;t show on the terminal for me right it&#8217;s pretty cool let&#8217;s go a little bit deeper into this</p>



<p class="wp-block-paragraph">i just want you to see real fast before i write an example program in assembly what you would</p>



<p class="wp-block-paragraph">probably end up doing in c plus plus so we usually do something like iostream in germane you know</p>



<p class="wp-block-paragraph">We&#8217;ll say using std cout std c error std and l and so forth.</p>



<p class="wp-block-paragraph">And then if you actually want to print a message to the user, we&#8217;ll say cout this message prints</p>



<p class="wp-block-paragraph">to std out because that&#8217;s what cout does by default.</p>



<p class="wp-block-paragraph">And then if we do c error, a lot of people haven&#8217;t actually seen this and I personally</p>



<p class="wp-block-paragraph">always forget that it&#8217;s even there if you print to see error it prints a message to standard error</p>



<p class="wp-block-paragraph">why would you want two different pipes that printed messages and one is called output and</p>



<p class="wp-block-paragraph">one is called error well like i&#8217;ve said before in other videos it&#8217;s really convenient to be able to</p>



<p class="wp-block-paragraph">have programs automate other programs for example if you have a program that is launching you know</p>



<p class="wp-block-paragraph">a second program maybe the second program fails in some way or wants to complain to you in some way</p>



<p class="wp-block-paragraph">or wants to complain to you in some way, it would usually, if it&#8217;s smart,</p>



<p class="wp-block-paragraph">print the complaint to standard error.</p>



<p class="wp-block-paragraph">It may not actually use C error because maybe it&#8217;s not a C++ program,</p>



<p class="wp-block-paragraph">but it would print to pipe number two, file descriptor number two, standard error.</p>



<p class="wp-block-paragraph">And then that way, the program that&#8217;s launching it can just sort of ignore messages</p>



<p class="wp-block-paragraph">that happen on standard output because we can assume all of those messages</p>



<p class="wp-block-paragraph">are just normal info messages that a human might want to see.</p>



<p class="wp-block-paragraph">Or maybe you want to record to a log or something somewhere</p>



<p class="wp-block-paragraph">log or something somewhere and just kind of save it away.</p>



<p class="wp-block-paragraph">But the error messages are a little bit more important than the regular,</p>



<p class="wp-block-paragraph">you know, normal messages.</p>



<p class="wp-block-paragraph">So if you&#8217;re automating another program,</p>



<p class="wp-block-paragraph">then your program probably wants to take standard output and either ignore it or</p>



<p class="wp-block-paragraph">just kind of send it to a different file.</p>



<p class="wp-block-paragraph">And then it wants to take standard error and pay more attention to it.</p>



<p class="wp-block-paragraph">Write it to a log file, save it, maybe check that it&#8217;s actually blank.</p>



<p class="wp-block-paragraph">And if it&#8217;s not empty, then maybe alarm bells go off.</p>



<p class="wp-block-paragraph">Something went wrong.</p>



<p class="wp-block-paragraph">We have to alert someone or, you know, make a database entry, send an email, whatever.</p>



<p class="wp-block-paragraph">And yeah, just pipe one and pipe two is how you accomplish that.</p>



<p class="wp-block-paragraph">So this is what&#8217;s happening in C++ when you do that sort of thing.</p>



<p class="wp-block-paragraph">Okay, so now I would like to write a sample program that just kind of demonstrates this</p>



<p class="wp-block-paragraph">real fast.</p>



<p class="wp-block-paragraph">So please bear with me.</p>



<p class="wp-block-paragraph">I&#8217;m going to go really fast for the assembly portion because this is not an assembly video.</p>



<p class="wp-block-paragraph">to learn more about how to write assembly in the first place than see my other videos.</p>



<p class="wp-block-paragraph">For now, I&#8217;m just going to create a little blank file here.</p>



<p class="wp-block-paragraph">Let&#8217;s see where the heck is my window.</p>



<p class="wp-block-paragraph">I&#8217;m on a multi-window system here.</p>



<p class="wp-block-paragraph">Okay, so I&#8217;m just going to paste a little data section.</p>



<p class="wp-block-paragraph">This is Yasm assembly.</p>



<p class="wp-block-paragraph">A little data section.</p>



<p class="wp-block-paragraph">I&#8217;m just going to fill it up with strings.</p>



<p class="wp-block-paragraph">I&#8217;m going to make a string for the introduction.</p>



<p class="wp-block-paragraph">Hello, the module has started.</p>



<p class="wp-block-paragraph">A string announcing everything that we&#8217;re going to do.</p>



<p class="wp-block-paragraph">We&#8217;re going to begin printing to standard output and standard error,</p>



<p class="wp-block-paragraph">and then some messages that will go to each.</p>



<p class="wp-block-paragraph">And then some messages that will go to each and then a standard input string, which we&#8217;ll</p>



<p class="wp-block-paragraph">talk about after the standard output and standard error.</p>



<p class="wp-block-paragraph">So just a bunch of strings.</p>



<p class="wp-block-paragraph">I&#8217;m going to make a buffer size.</p>



<p class="wp-block-paragraph">I&#8217;m going to make system call codes for reading, writing and exiting.</p>



<p class="wp-block-paragraph">If you want to know more about system call codes, see my other videos and some file descriptors.</p>



<p class="wp-block-paragraph">This is exactly what I just talked about.</p>



<p class="wp-block-paragraph">The file descriptor for standard input is zero for standard output is one for standard</p>



<p class="wp-block-paragraph">for standard error is two.</p>



<p class="wp-block-paragraph">And then I&#8217;m going to do a system exit code of zero,</p>



<p class="wp-block-paragraph">which actually doesn&#8217;t matter that much,</p>



<p class="wp-block-paragraph">but I&#8217;m going to do it.</p>



<p class="wp-block-paragraph">So now I&#8217;m going to make a, let&#8217;s see,</p>



<p class="wp-block-paragraph">a global,</p>



<p class="wp-block-paragraph">hmm, make a global.</p>



<p class="wp-block-paragraph">Oh, did I already make the text section?</p>



<p class="wp-block-paragraph">Here we go.</p>



<p class="wp-block-paragraph">So there&#8217;s the text section.</p>



<p class="wp-block-paragraph">So the data section is over now.</p>



<p class="wp-block-paragraph">So data section is over now.</p>



<p class="wp-block-paragraph">I&#8217;m going to make the tech section.</p>



<p class="wp-block-paragraph">I&#8217;m going to make a global entry point called start.</p>



<p class="wp-block-paragraph">Again, if you want to know more about assembly programming in general,</p>



<p class="wp-block-paragraph">see my other videos.</p>



<p class="wp-block-paragraph">But so this is the entry point of our program.</p>



<p class="wp-block-paragraph">At the very end, we should probably just program that it exits with success</p>



<p class="wp-block-paragraph">and test it out real fast.</p>



<p class="wp-block-paragraph">So basically right now this program does nothing.</p>



<p class="wp-block-paragraph">Let me just double check.</p>



<p class="wp-block-paragraph">Clear and make run.</p>



<p class="wp-block-paragraph">I have a make file under the hood, but this is not a make file video.</p>



<p class="wp-block-paragraph">If you want to know more about make files, see my other videos.</p>



<p class="wp-block-paragraph">know more about make files see my other videos but basically it just starts running and then</p>



<p class="wp-block-paragraph">it just dies right away okay no problem let me actually can i i want to fix that make file</p>



<p class="wp-block-paragraph">because it&#8217;s it&#8217;s labeled after like a different project that i was doing let&#8217;s do</p>



<p class="wp-block-paragraph">there&#8217;s no need for me to even do this i&#8217;m just uh i just can&#8217;t help myself okay so there we go</p>



<p class="wp-block-paragraph">going back to the editor.</p>



<p class="wp-block-paragraph">We have a program that does nothing.</p>



<p class="wp-block-paragraph">I&#8217;m going to copy paste in a couple of useful functions that I use elsewhere.</p>



<p class="wp-block-paragraph">Again, this is not an assembly video.</p>



<p class="wp-block-paragraph">So, so you can look at my code if you want to, if you just kind of want to know how this</p>



<p class="wp-block-paragraph">works, but not the point of this video.</p>



<p class="wp-block-paragraph">So I&#8217;m not going to spend too much time.</p>



<p class="wp-block-paragraph">Maybe I&#8217;ll just briefly talk about what it does, but not the point of this video.</p>



<p class="wp-block-paragraph">So the first thing I&#8217;m doing is I&#8217;m adding a function called print null terminated string</p>



<p class="wp-block-paragraph">function called print null terminated string just you know it sweeps through a</p>



<p class="wp-block-paragraph">string or actually it asks another function I made to find out how long the</p>



<p class="wp-block-paragraph">string is and then it&#8217;ll print the string to some file handle that I gave</p>



<p class="wp-block-paragraph">it like standard output or standard error and you know it calls on this other</p>



<p class="wp-block-paragraph">function called string length which I just wrote in pure assembly for fun even</p>



<p class="wp-block-paragraph">though I didn&#8217;t need to and it just kind of sweeps through the string until it</p>



<p class="wp-block-paragraph">finds a zero and then it knows how long the string is and then CRLF just prints</p>



<p class="wp-block-paragraph">is and then crlf just prints a carriage return new line uh carriage return new line just um</p>



<p class="wp-block-paragraph">with the same idea with the print null terminated string function and you can see all my strings have</p>



<p class="wp-block-paragraph">null terminators that&#8217;s the dot zero at the very end of it okay so we got those helper functions</p>



<p class="wp-block-paragraph">uh the next thing that i need to add in here is</p>



<p class="wp-block-paragraph">do an intro like my growling i used to have a professor who would go</p>



<p class="wp-block-paragraph">and he would go oh god when something went wrong and i do that all the time even when things are</p>



<p class="wp-block-paragraph">going right okay so i&#8217;m going to paste a little function here called intro and this is not going</p>



<p class="wp-block-paragraph">to be anything important it&#8217;s just going to print a little hello message you know it just uses my</p>



<p class="wp-block-paragraph">intro string and then just prints it with those other functions i made so that means now my my</p>



<p class="wp-block-paragraph">I can call intro real fast and then it&#8217;ll return when it&#8217;s done.</p>



<p class="wp-block-paragraph">If I just sort of run the program again, you can see after all the build messages,</p>



<p class="wp-block-paragraph">it&#8217;s just printing that the module has started.</p>



<p class="wp-block-paragraph">Okay, so nothing super important yet.</p>



<p class="wp-block-paragraph">Now, what I&#8217;d like to do is capture some incoming arguments real quick because…</p>



<p class="wp-block-paragraph">Let&#8217;s see standard input.</p>



<p class="wp-block-paragraph">Well, that&#8217;s actually not going to work.</p>



<p class="wp-block-paragraph">Let&#8217;s see what I want to do here.</p>



<p class="wp-block-paragraph">No, I think that&#8217;s part of a different program.</p>



<p class="wp-block-paragraph">OK, I&#8217;m going to call a demo.</p>



<p class="wp-block-paragraph">I don&#8217;t think I need to add that one thing that I was just looking at.</p>



<p class="wp-block-paragraph">So I&#8217;m going to call a function that&#8217;s going to be our main demo.</p>



<p class="wp-block-paragraph">So it&#8217;s going to jump down somewhere.</p>



<p class="wp-block-paragraph">I&#8217;ll just create the function down later.</p>



<p class="wp-block-paragraph">So let&#8217;s see.</p>



<p class="wp-block-paragraph">Where is it?</p>



<p class="wp-block-paragraph">Standard input.</p>



<p class="wp-block-paragraph">I&#8217;m going to start off by saying this is my standard input function which is this and</p>



<p class="wp-block-paragraph">is this pop p and then pop r12 and then it returns if you don&#8217;t know what a prologue</p>



<p class="wp-block-paragraph">and epilogue are or why I&#8217;m doing pushes and pops just see my other videos but basically</p>



<p class="wp-block-paragraph">I&#8217;m responsible for preserving it.</p>



<p class="wp-block-paragraph">And I&#8217;m going to use the base pointer to help me remember where the stack started.</p>



<p class="wp-block-paragraph">I&#8217;m just going to choose to…</p>



<p class="wp-block-paragraph">What did I do?</p>



<p class="wp-block-paragraph">I started the wrong function.</p>



<p class="wp-block-paragraph">I&#8217;m going to do that one later.</p>



<p class="wp-block-paragraph">Okay, for now, let me go find where that other one is.</p>



<p class="wp-block-paragraph">Oh, there it is.</p>



<p class="wp-block-paragraph">Should have double checked.</p>



<p class="wp-block-paragraph">I&#8217;m going way too fast.</p>



<p class="wp-block-paragraph">I&#8217;ll just copy paste this whole thing from my solution.</p>



<p class="wp-block-paragraph">So I&#8217;m going to do standard.</p>



<p class="wp-block-paragraph">This video is a mess.</p>



<p class="wp-block-paragraph">Honestly, it&#8217;s a mess, but that&#8217;s okay.</p>



<p class="wp-block-paragraph">I&#8217;m going to try my best to explain it.</p>



<p class="wp-block-paragraph">So I have this function standard output standard error and I&#8217;m calling it here.</p>



<p class="wp-block-paragraph">So it should jump right down there as soon as the program starts.</p>



<p class="wp-block-paragraph">The standard input one is not getting called yet, but we&#8217;ll call it at the end of this</p>



<p class="wp-block-paragraph">video.</p>



<p class="wp-block-paragraph">print null terminated string function to print a message to standard output.</p>



<p class="wp-block-paragraph">Remember standard output was just you know pipe one. Standard error is going to</p>



<p class="wp-block-paragraph">be pipe two. So if I go back here and I say I want to print this matches to that</p>



<p class="wp-block-paragraph">pipe then it&#8217;ll go to standard output just like the echo program was doing</p>



<p class="wp-block-paragraph">when we looked at it a moment ago. And then next we&#8217;re going to print to</p>



<p class="wp-block-paragraph">Oh, that was just an announcement that we&#8217;re going to begin.</p>



<p class="wp-block-paragraph">So this is the real message that will say this is definitely going to standard output.</p>



<p class="wp-block-paragraph">And then this other message is going to go to standard error, which is when we when we</p>



<p class="wp-block-paragraph">looked at C error or pipe number two a moment ago.</p>



<p class="wp-block-paragraph">So basically, I&#8217;m just printing an announcement and then two important messages.</p>



<p class="wp-block-paragraph">One is going to pipe one and one is going to pipe two for standard output and standard</p>



<p class="wp-block-paragraph">error.</p>



<p class="wp-block-paragraph">OK, like really not very complicated at all.</p>



<p class="wp-block-paragraph">Right.</p>



<p class="wp-block-paragraph">So if I run this program now, hopefully I didn&#8217;t crash it by copy pasting out of order here.</p>



<p class="wp-block-paragraph">Yeah, there we go.</p>



<p class="wp-block-paragraph">Clear and make run.</p>



<p class="wp-block-paragraph">So notice how it says that the messages are going to be printed.</p>



<p class="wp-block-paragraph">And then notice that both of my messages actually show up on the terminal.</p>



<p class="wp-block-paragraph">The one that says this message will print to standard output, number one, pipe one.</p>



<p class="wp-block-paragraph">This message will print to standard error, pipe two.</p>



<p class="wp-block-paragraph">They both get printed to the terminal because by default, the terminal will just take both of those pipes.</p>



<p class="wp-block-paragraph">both of those pipes it&#8217;ll take one and two standard output and error but I can</p>



<p class="wp-block-paragraph">use those little redirection tricks to mute one or more of those pipes so I&#8217;m</p>



<p class="wp-block-paragraph">gonna say pipe one which is standard output I&#8217;m just gonna redirect that to</p>



<p class="wp-block-paragraph">dev null to say I don&#8217;t want to see standard output if I run it again</p>



<p class="wp-block-paragraph">notice how the only thing you can see on the string or on the screen is standard</p>



<p class="wp-block-paragraph">error pipe to file descriptor 2 on the other hand if I redirect file descriptor</p>



<p class="wp-block-paragraph">descriptor to pipe two to nothing then I should see all the normal messages and not see the error</p>



<p class="wp-block-paragraph">message notice right here it&#8217;s it prints all the regular you know make file stuff and then the</p>



<p class="wp-block-paragraph">welcome message and then here&#8217;s our message that says this is going to be printed to standard output</p>



<p class="wp-block-paragraph">so notice how the error message is missing so cool if I mute both of those I can do that I can</p>



<p class="wp-block-paragraph">then nothing gets printed at all because that&#8217;s all we really have is standard output and standard</p>



<p class="wp-block-paragraph">error all right not too bad right that&#8217;s the basic idea between redirecting and things you</p>



<p class="wp-block-paragraph">could also do things like this if I okay this is not part of my plan but suppose I wanted to take</p>



<p class="wp-block-paragraph">any error message and redirect it to instead of dev null I wanted to redirect it to some kind of</p>



<p class="wp-block-paragraph">standard error.txt.</p>



<p class="wp-block-paragraph">Notice how nothing seems to have shown up on the screen, but if I list the directory,</p>



<p class="wp-block-paragraph">now there&#8217;s a text file called standard error that contains the error message.</p>



<p class="wp-block-paragraph">So you can redirect pipes, you can reattach them if you&#8217;re like an elite hacker.</p>



<p class="wp-block-paragraph">You can do lots of things with them, but that&#8217;s as far as I&#8217;m going to take it right now.</p>



<p class="wp-block-paragraph">I&#8217;m going to remove that.</p>



<p class="wp-block-paragraph">Now let&#8217;s look at standard input.</p>



<p class="wp-block-paragraph">How do you send input to the program?</p>



<p class="wp-block-paragraph">Remember when programs call other programs, they can send each other standard input too.</p>



<p class="wp-block-paragraph">It&#8217;s just that when I launch something on the terminal, I&#8217;m just, you know, I&#8217;m the</p>



<p class="wp-block-paragraph">human and so whatever I type or, you know, what command I type is going to go into standard</p>



<p class="wp-block-paragraph">input if I do it the right way.</p>



<p class="wp-block-paragraph">So let&#8217;s go back to the program here.</p>



<p class="wp-block-paragraph">Okay, so let&#8217;s finish up standard input.</p>



<p class="wp-block-paragraph">And let&#8217;s see the pre-made code that I had here.</p>



<p class="wp-block-paragraph">I had the prolog and the epilog, right?</p>



<p class="wp-block-paragraph">Move the base pointer</p>



<p class="wp-block-paragraph">RBP and R12. Oh, I got to put the</p>



<p class="wp-block-paragraph">Base pointer back into the stack pointer. Let&#8217;s see move</p>



<p class="wp-block-paragraph">Again, this is not an assembly video. So just try to hang on here. So what I&#8217;m gonna do in this video</p>



<p class="wp-block-paragraph">I thought I was cute when I was making this plan. I know I&#8217;m not like that clever, but um, I</p>



<p class="wp-block-paragraph">Thought hey wouldn&#8217;t it be fun instead of having a global</p>



<p class="wp-block-paragraph">or the BSS section. What if I just made the stack a buffer? This is kind of what you do when you make</p>



<p class="wp-block-paragraph">a local array in C++. You&#8217;re making a buffer on the stack. So this is not a stack pointer video.</p>



<p class="wp-block-paragraph">So long story short, I&#8217;m just going to keep track of where the stack pointer started with this base</p>



<p class="wp-block-paragraph">pointer. That&#8217;s why I have to preserve it there. And then I&#8217;m just going to subtract my buffer size</p>



<p class="wp-block-paragraph">from the stack pointer. And what is the buffer size? I&#8217;ve chosen to do a buffer size of about</p>



<p class="wp-block-paragraph">So that means the user or me, I could send about eight kilobytes, maybe eight kilobytes</p>



<p class="wp-block-paragraph">or less into standard input and be sure that it&#8217;s all actually going to be received by</p>



<p class="wp-block-paragraph">the program.</p>



<p class="wp-block-paragraph">And then I&#8217;m just going to use R12 to remember where the start of the buffer is, which is</p>



<p class="wp-block-paragraph">just wherever the stack pointer started.</p>



<p class="wp-block-paragraph">Because if we subtract and then the data that increases is actually increasing in memory,</p>



<p class="wp-block-paragraph">but making room on the stack decreased, it&#8217;s just the way it works.</p>



<p class="wp-block-paragraph">There&#8217;s going to be another stack video out there.</p>



<p class="wp-block-paragraph">stack video out there anyway for now I just create a buffer on the stack and</p>



<p class="wp-block-paragraph">then I&#8217;m gonna print a little hello message so I&#8217;m gonna print this so just</p>



<p class="wp-block-paragraph">my message saying hey we&#8217;re about to do something from standard input and then</p>



<p class="wp-block-paragraph">I&#8217;m gonna send that to a standard output so the message is gonna go to standard</p>



<p class="wp-block-paragraph">output but I&#8217;m announcing that we&#8217;re about to read from standard input</p>



<p class="wp-block-paragraph">assuming I actually cleaned up correctly let me double check this this should</p>



<p class="wp-block-paragraph">It should just simply say that it&#8217;s going to without crashing.</p>



<p class="wp-block-paragraph">Okay, looks good.</p>



<p class="wp-block-paragraph">So then now I&#8217;m ready to actually read from standard input.</p>



<p class="wp-block-paragraph">We&#8217;re going to use a system call from this.</p>



<p class="wp-block-paragraph">If you want more information on system calls, see my other videos.</p>



<p class="wp-block-paragraph">But basically you just go to the system call codes table,</p>



<p class="wp-block-paragraph">look up appendix area of whatever textbook you&#8217;re using.</p>



<p class="wp-block-paragraph">And you say, what&#8217;s the code to read?</p>



<p class="wp-block-paragraph">I want the system to read.</p>



<p class="wp-block-paragraph">what you know i want the system to read so i define that as system read and if you look up</p>



<p class="wp-block-paragraph">here in my program it&#8217;s just call code zero so sys call code zero is to read from somewhere</p>



<p class="wp-block-paragraph">and then uh where do i want to read from that&#8217;s the second argument for the standard</p>



<p class="wp-block-paragraph">or for the system call i want to read from standard input that&#8217;s going to be the number zero</p>



<p class="wp-block-paragraph">if you recall and then here is a pointer to the first character of wherever i want it to</p>



<p class="wp-block-paragraph">read into. So it&#8217;s going to read from that pipe, but it has to, it has to write the data that it</p>



<p class="wp-block-paragraph">read somewhere so that I can save it and access it. So R12 is basically going to be a bunch of</p>



<p class="wp-block-paragraph">free bytes that I created on the stack. So I like, you know, I&#8217;m, I like made the stack bigger,</p>



<p class="wp-block-paragraph">but it&#8217;s mostly empty or with junk data. And R12 is just pointing to the first byte that I have</p>



<p class="wp-block-paragraph">reserved. So, you know, you could imagine maybe you make a global variable in the BSS section up</p>



<p class="wp-block-paragraph">up at the top, you know, like an eight kilobyte array of bytes, and then just sort of point</p>



<p class="wp-block-paragraph">it to that. But in my case, I&#8217;m just using the stack because I think it&#8217;s cooler. So</p>



<p class="wp-block-paragraph">I tell it, Hey, that&#8217;s the first bite on the stack that you want that I want you to start</p>



<p class="wp-block-paragraph">reading from. And then I give it the buffer size, which we just looked at. And then I</p>



<p class="wp-block-paragraph">do a system call and then the system now should do all the hard work for me. It&#8217;ll look at</p>



<p class="wp-block-paragraph">the pipe for standard input. It&#8217;ll grab all of it. And then it will only grab, you know,</p>



<p class="wp-block-paragraph">it&#8217;ll stop if the input ends before that and then when I&#8217;m done I should be able</p>



<p class="wp-block-paragraph">to actually read from the buffer which is sitting at R12 and print it to the</p>



<p class="wp-block-paragraph">screen so the next thing I&#8217;m gonna copy paste in there is I&#8217;m gonna print what</p>



<p class="wp-block-paragraph">I just read from standard input so this is another call to my function my little</p>



<p class="wp-block-paragraph">doggy wants to go pee even though he&#8217;s completely lying he just went pee so at</p>



<p class="wp-block-paragraph">wants to go outside and lift his leg and do nothing and then come back in and demand a treat.</p>



<p class="wp-block-paragraph">I&#8217;ll let him do it in a few minutes just in case but trust me he&#8217;s lying he&#8217;s laid like five times</p>



<p class="wp-block-paragraph">today. Anyway I sometimes I regret teaching him to growl at me. It&#8217;s so cute but like it&#8217;s not</p>



<p class="wp-block-paragraph">cute right now. I don&#8217;t know maybe it is. Let me know in the comments. So basically I&#8217;m going to</p>



<p class="wp-block-paragraph">take that R12 buffer that I just wrote to and I&#8217;m going to print that directly to standard output</p>



<p class="wp-block-paragraph">output and this is not really the important part of the video.</p>



<p class="wp-block-paragraph">So I&#8217;m going to do that and then I&#8217;m going to kind of clean up here at the end of the</p>



<p class="wp-block-paragraph">function.</p>



<p class="wp-block-paragraph">And then maybe I&#8217;ll say goodbye.</p>



<p class="wp-block-paragraph">I think I just added a string for that.</p>



<p class="wp-block-paragraph">So maybe I&#8217;ll say goodbye.</p>



<p class="wp-block-paragraph">I&#8217;ll say goodbye before we end the function and then I&#8217;ll actually return.</p>



<p class="wp-block-paragraph">So let me go here and run the program.</p>



<p class="wp-block-paragraph">Let&#8217;s see, begin.</p>



<p class="wp-block-paragraph">printed because we didn&#8217;t send anything and we also didn&#8217;t call that let me call</p>



<p class="wp-block-paragraph">standard input call stdin and so now it&#8217;s actually gonna print basically</p>



<p class="wp-block-paragraph">nothing oh I didn&#8217;t send it anything so it&#8217;s just kind of hanging you probably</p>



<p class="wp-block-paragraph">want to check this sort of situation but that&#8217;s that&#8217;s not the point of this</p>



<p class="wp-block-paragraph">video let me show you how to pipe some some stuff into standard input real fast</p>



<p class="wp-block-paragraph">hello and then just put a little or bar in the shell this will take the output</p>



<p class="wp-block-paragraph">of echo and instead of printing it to the terminal it&#8217;ll attach its standard</p>



<p class="wp-block-paragraph">output into the standard input of make run pretty cool shell trick so now we</p>



<p class="wp-block-paragraph">should see the word hello the word hello printed and that&#8217;s what it does we have</p>



<p class="wp-block-paragraph">detected the following stdin and it says like here&#8217;s begin that&#8217;s just a string</p>



<p class="wp-block-paragraph">that I had that I print every time and then here&#8217;s the string that it actually</p>



<p class="wp-block-paragraph">And then it ends.</p>



<p class="wp-block-paragraph">Pretty nice.</p>



<p class="wp-block-paragraph">I think maybe we could probably do the empty thing if I just started typing here.</p>



<p class="wp-block-paragraph">And then maybe I hit control D to detach the buffer.</p>



<p class="wp-block-paragraph">And yeah, that&#8217;s what it does.</p>



<p class="wp-block-paragraph">It sort of prints here and then it ends there.</p>



<p class="wp-block-paragraph">Didn&#8217;t do a new line.</p>



<p class="wp-block-paragraph">I think it probably doubled it for some reason because I…</p>



<p class="wp-block-paragraph">Let&#8217;s see.</p>



<p class="wp-block-paragraph">I didn&#8217;t plan for this.</p>



<p class="wp-block-paragraph">Let me see.</p>



<p class="wp-block-paragraph">plan for this let me see it printed oh because I did I did not null terminate the string so</p>



<p class="wp-block-paragraph">actually what it did is it uh let&#8217;s see if we can do that real fast one more time I&#8217;m going to go</p>



<p class="wp-block-paragraph">one two three four five then I&#8217;m going to just disconnect the standard input buffer because the</p>



<p class="wp-block-paragraph">printing function needs a null terminator to know when to stop there&#8217;s not going to be a null</p>



<p class="wp-block-paragraph">terminator because I just typed and disconnected the uh the input so it&#8217;s actually going to just</p>



<p class="wp-block-paragraph">until it randomly finds a zero and then it&#8217;ll stop so if I disconnect it it</p>



<p class="wp-block-paragraph">that explanation was bunk let me try that one more time I&#8217;m gonna go a bunch</p>



<p class="wp-block-paragraph">of H&#8217;s I guess there is a null terminator I disconnect it no no see how</p>



<p class="wp-block-paragraph">yeah these little symbols there so it does kind of print until it finds a</p>



<p class="wp-block-paragraph">null terminator but I guess I was confused because it seemed like it</p>



<p class="wp-block-paragraph">like it printed it twice what&#8217;s actually happening is when i type then it&#8217;s getting sent to the</p>



<p class="wp-block-paragraph">terminal which and that&#8217;s not part of the program that we just wrote then when i disconnect standard</p>



<p class="wp-block-paragraph">input then the program finally prints everything that i actually typed until it hits a null</p>



<p class="wp-block-paragraph">terminator in this case it looks like it seems to have worked but uh if i just do like a couple</p>



<p class="wp-block-paragraph">sevens and then disconnect probably have to do this a bunch of times before we&#8217;ll see those weird</p>



<p class="wp-block-paragraph">What did I do? Hit enter. That seems to have worked. My dog is stressing me out</p>



<p class="wp-block-paragraph">but I love him. Alright anyway just trust me on this sometimes it&#8217;s hitting the</p>



<p class="wp-block-paragraph">null terminator in time sometimes it&#8217;s not. But I hope by now you understand the</p>



<p class="wp-block-paragraph">difference between standard input standard output and standard error. Thank</p>



<p class="wp-block-paragraph">you so much for watching this video that I&#8217;m recording and I hope you learned a</p>



<p class="wp-block-paragraph">little bit of stuff and had a little bit of fun. I&#8217;m gonna let my dog lie to me</p>



<p class="wp-block-paragraph">I&#8217;m gonna let my dog lie to me for a second and I&#8217;ll see you in the next video.</p>



<p class="wp-block-paragraph">Hey everybody, thanks for watching this video again from the bottom of my heart.</p>



<p class="wp-block-paragraph">I really appreciate it.</p>



<p class="wp-block-paragraph">I do hope you did learn something and have some fun.</p>



<p class="wp-block-paragraph">If you could do me a please, a small little favor, could you please subscribe and follow</p>



<p class="wp-block-paragraph">this channel or these videos or whatever it is you do on the current social media website</p>



<p class="wp-block-paragraph">that you&#8217;re looking at right now.</p>



<p class="wp-block-paragraph">It would really mean the world to me and it&#8217;ll help make more videos and grow this community.</p>



<p class="wp-block-paragraph">and grow this community so we&#8217;ll be able to do more videos, longer videos, better videos,</p>



<p class="wp-block-paragraph">or just I&#8217;ll be able to keep making videos in general. So please do me a kindness and subscribe.</p>



<p class="wp-block-paragraph">You know, sometimes I&#8217;m sleeping in the middle of the night and I just wake up because I know</p>



<p class="wp-block-paragraph">somebody subscribed or followed. It just wakes me up and I get filled with joy. That&#8217;s exactly what</p>



<p class="wp-block-paragraph">happens every single time. So you could do it as a nice favor to me or you could troll me if you</p>



<p class="wp-block-paragraph">want to just wake me up in the middle of the night, just subscribe and then I&#8217;ll just wake up.</p>



<p class="wp-block-paragraph">wake up I promise that&#8217;s what will happen also if you look at the middle of</p>



<p class="wp-block-paragraph">the screen right now you should see a QR code which you can scan in order to go</p>



<p class="wp-block-paragraph">to the website which I think is also named somewhere at the bottom of this</p>



<p class="wp-block-paragraph">video and it&#8217;ll take you to my main website where you can just kind of like</p>



<p class="wp-block-paragraph">see all the videos I published and the services and tutorials and things that I</p>



<p class="wp-block-paragraph">offer and all that good stuff and if you have a suggestion for clarifications or</p>



<p class="wp-block-paragraph">or errata or just future videos that you want to see please leave a comment or if you just want to</p>



<p class="wp-block-paragraph">say hey what&#8217;s up what&#8217;s going on you know just send me a comment whatever i also wake up for</p>



<p class="wp-block-paragraph">those in the middle of the night i get i wake up in a cold sweat and i&#8217;m like it would really it</p>



<p class="wp-block-paragraph">really mean the world to me i would really appreciate it so again thank you so much for</p>



<p class="wp-block-paragraph">watching this video and um enjoy the cool music as as i fade into the darkness which is coming for us</p>



<p class="wp-block-paragraph">Thank you.</p>
<p>The post <a href="https://www.NeuralLantern.com/mastering-standard-input-output-and-error-stdin-stdout-stderr-in-linux-with-yasm-assembly-examples/">Mastering Standard Input, Output, and Error (STDIN, STDOUT, STDERR) in Linux with Yasm Assembly Examples</a> appeared first on <a href="https://www.NeuralLantern.com">NeuralLantern.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.NeuralLantern.com/mastering-standard-input-output-and-error-stdin-stdout-stderr-in-linux-with-yasm-assembly-examples/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Mastering System Services in x86-64 Assembly Programming</title>
		<link>https://www.NeuralLantern.com/mastering-system-services-in-x86-64-assembly-programming/</link>
					<comments>https://www.NeuralLantern.com/mastering-system-services-in-x86-64-assembly-programming/#respond</comments>
		
		<dc:creator><![CDATA[mike]]></dc:creator>
		<pubDate>Mon, 18 Aug 2025 14:42:23 +0000</pubDate>
				<category><![CDATA[Assembly Language]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Videos]]></category>
		<category><![CDATA[assembly language]]></category>
		<category><![CDATA[assembly programming]]></category>
		<category><![CDATA[coding tutorials]]></category>
		<category><![CDATA[computer science]]></category>
		<category><![CDATA[exit codes]]></category>
		<category><![CDATA[file descriptors]]></category>
		<category><![CDATA[file operations]]></category>
		<category><![CDATA[low-level programming]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[standard output]]></category>
		<category><![CDATA[syscalls]]></category>
		<category><![CDATA[system calls]]></category>
		<category><![CDATA[system services]]></category>
		<category><![CDATA[x86-64 assembly]]></category>
		<category><![CDATA[Yasm assembly]]></category>
		<guid isPermaLink="false">https://www.NeuralLantern.com/?p=205</guid>

					<description><![CDATA[<p>Learn x86-64 assembly system services! Master syscalls, file descriptors, and program exits with clear examples in this coding tutorial. #AssemblyProgramming</p>
<p>The post <a href="https://www.NeuralLantern.com/mastering-system-services-in-x86-64-assembly-programming/">Mastering System Services in x86-64 Assembly Programming</a> appeared first on <a href="https://www.NeuralLantern.com">NeuralLantern.com</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<figure class="wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
<iframe title="Mastering System Services in x86-64 Assembly Programming" width="1380" height="776" src="https://www.youtube.com/embed/-ukGDzRNTxU?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
</div></figure>



<p class="wp-block-paragraph">Ready to master x86-64 assembly? This video breaks down system services, showing you how to use syscalls to print messages, handle file descriptors, and exit programs cleanly. We’ll walk through a real assembly program, explain key concepts like standard output and file handles, and share tips from a top book on the subject. Whether you’re new to assembly or sharpening your skills, this tutorial is packed with clear examples and practical advice. Subscribe for more coding deep dives, and check out our upcoming file I/O video! #AssemblyProgramming #SystemCalls #x86_64 #CodingTutorials</p>



<p class="wp-block-paragraph">Introduction to System Services 00:00:00<br>System Services in x86-64 Assembly 00:00:04<br>Recommended Book on Assembly 00:00:35<br>What is a System Service? 00:01:01<br>Example Assembly Program 00:01:21<br>Syscall Instruction Explanation 00:02:52<br>Standard Output and File Descriptors 00:04:01<br>Printing a String with Syscall 00:05:16<br>Exiting a Program with Syscall 00:07:21<br>Exit Codes and Program Success 00:08:02<br>Book Reference for System Services 00:09:51<br>Detailed System Write Service 00:11:01<br>Checking System Call Return Values 00:12:08<br>File Operations with System Calls 00:14:35<br>Closing Files and Best Practices 00:15:50<br>Other System Call Codes 00:16:43<br>File Permissions and Modes 00:17:20<br>Handling System Call Results 00:19:03<br>Future Video Plans and Wrap-Up 00:20:40<br>Call to Subscribe and Outro 00:21:28</p>



<p class="wp-block-paragraph">Thanks for watching!</p>



<p class="wp-block-paragraph">Find us on other social media here:</p>



<ul class="wp-block-list">
<li>https://www.NeuralLantern.com/social</li>
</ul>



<p class="wp-block-paragraph">Please help support us!</p>



<ul class="wp-block-list">
<li>Subscribing + Sharing on Social Media</li>



<li>Leaving a comment or suggestion</li>



<li>Subscribing to our Blog</li>



<li>Watching the main &#8220;pinned&#8221; video of this channel for offers and extras</li>
</ul>



<p class="wp-block-paragraph">Hey everybody in this video we&#8217;re going to talk a little bit about system services</p>



<p class="wp-block-paragraph">in an x86-64 machine while programming in assembly</p>



<p class="wp-block-paragraph">this video is going to focus on yasm assembly but this should also work for any other assembly</p>



<p class="wp-block-paragraph">language that you program as long as you have the right kind of cpu x86-64 is also known as</p>



<p class="wp-block-paragraph">that in mind okay so for starters let&#8217;s see here&#8217;s a wonderful book i love pushing this book i did</p>



<p class="wp-block-paragraph">not write it the person who wrote it is a genius it&#8217;s called x86 64 assembly language programming</p>



<p class="wp-block-paragraph">with the boot to it&#8217;s a free and open source book so anybody can go get it find his website</p>



<p class="wp-block-paragraph">and here&#8217;s the version i&#8217;m using and honestly a really old version of this book is still really</p>



<p class="wp-block-paragraph">good he just keeps you know making little improvements but it was it was good even a</p>



<p class="wp-block-paragraph">even a long time ago. Anyway, so what is a system service? For starters, before I go into this book</p>



<p class="wp-block-paragraph">a little bit more, what is the system service? Suppose for the sake of argument that I&#8217;ve</p>



<p class="wp-block-paragraph">already written an assembly program, a pure assembly program, not a hybrid module program</p>



<p class="wp-block-paragraph">or anything. If you want to learn assembly, see my other videos, but for now I&#8217;m just going to</p>



<p class="wp-block-paragraph">assume you kind of already know how, so I&#8217;m just going to open up a pre-made program here.</p>



<p class="wp-block-paragraph">I&#8217;m going to do nano so I can edit the assembly file just so you can see what&#8217;s inside of here.</p>



<p class="wp-block-paragraph">just so you can see what&#8217;s inside of here.</p>



<p class="wp-block-paragraph">Okay, so I hope the red is not too hard to see.</p>



<p class="wp-block-paragraph">Oh, the tabs got ruined on Nano.</p>



<p class="wp-block-paragraph">Hang on, let me see if I can just open this up in Genie.</p>



<p class="wp-block-paragraph">Should have done that to begin with, okay.</p>



<p class="wp-block-paragraph">Yeah, okay, I wrote it in Genie</p>



<p class="wp-block-paragraph">and I guess I don&#8217;t have the tabs set up in Nano very well.</p>



<p class="wp-block-paragraph">Okay, so here&#8217;s like my assembly program.</p>



<p class="wp-block-paragraph">You know, I just have a little string here</p>



<p class="wp-block-paragraph">string length and CRLF for like a line feed and some file descriptors and stuff</p>



<p class="wp-block-paragraph">that I talk about in other videos here&#8217;s the entry point of the program just like</p>



<p class="wp-block-paragraph">a little start entry point because it&#8217;s pure assembly and all I&#8217;m gonna do is</p>



<p class="wp-block-paragraph">I&#8217;m gonna print a message right I&#8217;m just gonna print a little hello message and</p>



<p class="wp-block-paragraph">then call on CRLF all CRLF does is just it just prints a new line so the program</p>



<p class="wp-block-paragraph">if i run it right now you&#8217;ll just see what happens if i say let&#8217;s see clear and make run</p>



<p class="wp-block-paragraph">then you can see there&#8217;s some stuff happening up here in the make file which i forgot to update</p>



<p class="wp-block-paragraph">the title ignore that basically the real action is this line right here hello i&#8217;m printing using</p>



<p class="wp-block-paragraph">a system service if you already know assembly then you have probably already seen this before</p>



<p class="wp-block-paragraph">and it seems a little boring that&#8217;s good but i just want you to know that we&#8217;re using a system</p>



<p class="wp-block-paragraph">system service to actually do the printing.</p>



<p class="wp-block-paragraph">Kind of take it for granted here.</p>



<p class="wp-block-paragraph">This little instruction called syscall.</p>



<p class="wp-block-paragraph">What is a syscall?</p>



<p class="wp-block-paragraph">Well, it&#8217;s just basically you set up some variables, some,</p>



<p class="wp-block-paragraph">some codes, some data, whatever in, in some special registers.</p>



<p class="wp-block-paragraph">One of the registers lets the system know what you want it to do.</p>



<p class="wp-block-paragraph">One of the registers is like, or I guess all the following registers</p>



<p class="wp-block-paragraph">if they&#8217;re needed, are just input to the system call that you&#8217;re trying to do.</p>



<p class="wp-block-paragraph">do so in this case rax is letting the system know i want you to do this this code i want you to do</p>



<p class="wp-block-paragraph">this certain thing i have a defined set up here called system right but if you look up in my</p>



<p class="wp-block-paragraph">little defines area it&#8217;s just a number one so that means if i set the number one in rax i&#8217;m letting</p>



<p class="wp-block-paragraph">the system know that i want it to write to some pipe to some file then you know depending on what</p>



<p class="wp-block-paragraph">code you&#8217;re using rdi rsi rdx and other things may be needed or maybe not be needed at all</p>



<p class="wp-block-paragraph">in this case when i&#8217;m writing somewhere it wants three arguments so i have to use rdi rsi and rdx</p>



<p class="wp-block-paragraph">because those are the three arguments the first argument that it wants is where to print</p>



<p class="wp-block-paragraph">see my other videos for a more in-depth explanation of file descriptors and pipes but just long story</p>



<p class="wp-block-paragraph">pipes standard input standard output and standard error standard out is a pipe</p>



<p class="wp-block-paragraph">number one let&#8217;s see where&#8217;s that yeah it&#8217;s just assigned a number one so</p>



<p class="wp-block-paragraph">every program has its own number one pipe which is just standard output and I</p>



<p class="wp-block-paragraph">guess I should say that it gets piped to file descriptor one it&#8217;s kind of like an</p>



<p class="wp-block-paragraph">ambiguous term sort of but the system right call will write data to a file</p>



<p class="wp-block-paragraph">file and if i give it a file handle of just one that lets the system know oh actually i want to</p>



<p class="wp-block-paragraph">write to this standard output for the one particular process that we&#8217;re inside of but</p>



<p class="wp-block-paragraph">you could open any file that you want and get like a file handle to it and the operating system will</p>



<p class="wp-block-paragraph">realize oh you know i i associate that file handle i gave you with this certain open file that you</p>



<p class="wp-block-paragraph">created or opened for reading or whatever um and so when you give the handle back it knows where</p>



<p class="wp-block-paragraph">knows where to write. So in this case,</p>



<p class="wp-block-paragraph">it&#8217;s treating the standard output just like a file,</p>



<p class="wp-block-paragraph">just a file with a special handle of just one.</p>



<p class="wp-block-paragraph">I&#8217;ll talk about that more in another video.</p>



<p class="wp-block-paragraph">Then the next two arguments it wants is just the,</p>



<p class="wp-block-paragraph">a pointer to the first character of the message that you want to print.</p>



<p class="wp-block-paragraph">And then just an integer representing the length of the message that you want</p>



<p class="wp-block-paragraph">to print. And if we just look up here again at my little hello,</p>



<p class="wp-block-paragraph">my hello symbol points to an array of bytes, just characters.</p>



<p class="wp-block-paragraph">bytes just characters there is no null terminator on there it&#8217;s just bytes only</p>



<p class="wp-block-paragraph">and so when I give it you know message hello by itself what I&#8217;m really giving</p>



<p class="wp-block-paragraph">it is a pointer to that H letter just a pointer to the memory look you know I&#8217;m</p>



<p class="wp-block-paragraph">pointing to the memory location of the very first character in that string and</p>



<p class="wp-block-paragraph">then for the length I&#8217;m just using a special token little shortcut thing</p>



<p class="wp-block-paragraph">where you just put a dollar sign minus and then the name of another string and</p>



<p class="wp-block-paragraph">and then the name of another string,</p>



<p class="wp-block-paragraph">and then the assembler will compute the length of that string.</p>



<p class="wp-block-paragraph">So this right here is the same thing as me</p>



<p class="wp-block-paragraph">just typing the exact length of the string.</p>



<p class="wp-block-paragraph">I don&#8217;t even know what it is.</p>



<p class="wp-block-paragraph">I don&#8217;t feel like counting it.</p>



<p class="wp-block-paragraph">You can at home if you want.</p>



<p class="wp-block-paragraph">One, two, three, four, I&#8217;m not gonna do it.</p>



<p class="wp-block-paragraph">Anyway, so we basically just say,</p>



<p class="wp-block-paragraph">you know, I would like to write somewhere.</p>



<p class="wp-block-paragraph">I would like to write to the standard output file,</p>



<p class="wp-block-paragraph">file handle, I would like to, you know, to that pipe.</p>



<p class="wp-block-paragraph">I would like to write, you know, this string,</p>



<p class="wp-block-paragraph">you know this string and then i would like to tell you that this is how long that string is</p>



<p class="wp-block-paragraph">and then after you set all that stuff up you just say system call and the system will go ahead and</p>



<p class="wp-block-paragraph">do all of the hard work for you it&#8217;ll go figure out how to actually write data to the file and</p>



<p class="wp-block-paragraph">you know figure out how to do everything that it&#8217;s supposed to do and all you have to do is</p>



<p class="wp-block-paragraph">a little system call here right after this you can see that i have a call crlf that&#8217;s just a function</p>



<p class="wp-block-paragraph">call i talked about functions in other videos but basically you know i&#8217;m just calling a function here</p>



<p class="wp-block-paragraph">you know i&#8217;m just calling a function here and it does the same thing it makes a system call but</p>



<p class="wp-block-paragraph">instead of printing the hello string it&#8217;s printing my crlf string and if you just kind of look at what</p>



<p class="wp-block-paragraph">my crlf is it&#8217;s just these two characters 13 and 10 so like you know slash r slash n for carriage</p>



<p class="wp-block-paragraph">return line feed that&#8217;s why i call it crlf so all this program does just print a message and then a</p>



<p class="wp-block-paragraph">new line and then at the very end it does another system call to properly exit the program if this</p>



<p class="wp-block-paragraph">hybrid program and I had like the entry point of main, you know, that the GCC libraries give you,</p>



<p class="wp-block-paragraph">then I would probably just want to return at the end of this function. But since this is pure</p>



<p class="wp-block-paragraph">assembly, I can actually just exit the program and be fine. So exit with success is a different</p>



<p class="wp-block-paragraph">system call code. Notice how I have the symbol system exit loaded into RAX. And if you look up</p>



<p class="wp-block-paragraph">here, system exit is just the code 60. So if I send a code of one into RAX, that means I want to write</p>



<p class="wp-block-paragraph">a code of 60 somewhere that means i want to exit the program the only argument that takes is rdi</p>



<p class="wp-block-paragraph">which is just what is the exit code that you want to return to the operating system so um</p>



<p class="wp-block-paragraph">if you recall from some of my other videos let&#8217;s see if we do echo hello echo always succeeds at</p>



<p class="wp-block-paragraph">least as far as i know there&#8217;s like it&#8217;s like really hard to make it fail if i echo hello then</p>



<p class="wp-block-paragraph">the program echo launches and it will succeed by just printing the word hello like see how it just</p>



<p class="wp-block-paragraph">like see how it just does that so that means after that command i could echo the special</p>



<p class="wp-block-paragraph">variable dollar sign question mark just to see what the echo command exited with right it should</p>



<p class="wp-block-paragraph">be a zero because it succeeded so you can see now a zero under the hello on the other hand</p>



<p class="wp-block-paragraph">if i concatenate um let&#8217;s say a file that exists i should also get you know an error code that is a</p>



<p class="wp-block-paragraph">So it&#8217;s a zero at the very end.</p>



<p class="wp-block-paragraph">But if I try to concatenate a file that doesn&#8217;t actually exist,</p>



<p class="wp-block-paragraph">I&#8217;ll put a OS release two because that doesn&#8217;t exist.</p>



<p class="wp-block-paragraph">Notice how the cat command fails because it couldn&#8217;t find the file and the exit</p>



<p class="wp-block-paragraph">code is a one.</p>



<p class="wp-block-paragraph">So all you&#8217;re doing when setting RDI here is just controlling what exit code you</p>



<p class="wp-block-paragraph">want your program to exit with.</p>



<p class="wp-block-paragraph">This isn&#8217;t very convenient for a human running a program.</p>



<p class="wp-block-paragraph">Maybe if you want to look at the exit code for some reason, but this is really,</p>



<p class="wp-block-paragraph">really convenient for programs that want to automate other programs.</p>



<p class="wp-block-paragraph">programs just keep in mind if you have a program that is executing another</p>



<p class="wp-block-paragraph">program and it wants to see if that program succeeded the exit code is one</p>



<p class="wp-block-paragraph">of the easiest ways to find out if the program succeeded so this is the whole</p>



<p class="wp-block-paragraph">idea of this entire program we&#8217;re just using two system calls to print</p>



<p class="wp-block-paragraph">something and then to exit the program hopefully this makes sense and now I</p>



<p class="wp-block-paragraph">want to go show you this wonderful wonderful book if I didn&#8217;t already say</p>



<p class="wp-block-paragraph">If I didn&#8217;t already say this before, sorry if I already did.</p>



<p class="wp-block-paragraph">This book is written by a genius.</p>



<p class="wp-block-paragraph">It&#8217;s called this.</p>



<p class="wp-block-paragraph">Here&#8217;s the guy who wrote the book.</p>



<p class="wp-block-paragraph">And here&#8217;s the version that I&#8217;m using, but old versions are good.</p>



<p class="wp-block-paragraph">You can get this book for free on his website if you go find it.</p>



<p class="wp-block-paragraph">So I&#8217;m just going to go to this assembly book, which deals with a lot of Yasm assembly tips</p>



<p class="wp-block-paragraph">and tricks and tutorials and explanations and things.</p>



<p class="wp-block-paragraph">And I&#8217;m going to go to the section labeled after system services.</p>



<p class="wp-block-paragraph">So for me, this is a chapter 13 system services, just to give you a little explanation of what</p>



<p class="wp-block-paragraph">this is.</p>



<p class="wp-block-paragraph">You know, this is basically what I said.</p>



<p class="wp-block-paragraph">It gives you, you know, a chance for your application to ask the operating system to</p>



<p class="wp-block-paragraph">do something for you that you don&#8217;t want to program from scratch in assembly or that you</p>



<p class="wp-block-paragraph">can&#8217;t program.</p>



<p class="wp-block-paragraph">But here&#8217;s the real juicy details here.</p>



<p class="wp-block-paragraph">If we go to, yeah, yeah.</p>



<p class="wp-block-paragraph">Okay.</p>



<p class="wp-block-paragraph">C, which is section 23.0 system services.</p>



<p class="wp-block-paragraph">There&#8217;s a whole bunch of system services in here that you can, uh, that you can read about.</p>



<p class="wp-block-paragraph">So for starters, if we go down a little bit, notice how it says basic system services.</p>



<p class="wp-block-paragraph">If we go down a little bit, you can see right here, the system write service that we&#8217;ve</p>



<p class="wp-block-paragraph">been using in the sample assembly program.</p>



<p class="wp-block-paragraph">You know, when we&#8217;re just printing, we say code one is to write something.</p>



<p class="wp-block-paragraph">And so this is what the table says.</p>



<p class="wp-block-paragraph">you place inside of RAX before syscall.</p>



<p class="wp-block-paragraph">Call code 1 is going to be to write characters and then it tells you what arguments it needs.</p>



<p class="wp-block-paragraph">So like RDI is the file descriptor where do you want to write to.</p>



<p class="wp-block-paragraph">Just like I said before you could give it a file handle that you already received from</p>



<p class="wp-block-paragraph">opening a file or creating a file.</p>



<p class="wp-block-paragraph">Or you could give it 0 or 1 or 2 if you want to try to write to one of the pipes although</p>



<p class="wp-block-paragraph">actually file descriptor 0 is standard input I don&#8217;t think that would actually work.</p>



<p class="wp-block-paragraph">zero to reading if you wanted to read the user&#8217;s input or or you know any input that that program</p>



<p class="wp-block-paragraph">was given through its standard input rsi is just the address of the characters to write like we</p>



<p class="wp-block-paragraph">talked about before and then rdx is the count of the characters to write notice how there are no</p>



<p class="wp-block-paragraph">more arguments and that&#8217;s why i only gave it three arguments besides rex notice how it says here if</p>



<p class="wp-block-paragraph">unsuccessful it returns a negative value if successful it returns the count of characters</p>



<p class="wp-block-paragraph">count of characters actually written this is a really really good idea if you think about it</p>



<p class="wp-block-paragraph">um a lot of new programmers they don&#8217;t really look at return codes when they call system services</p>



<p class="wp-block-paragraph">or built-in c functions or built-in c++ functions they just kind of call it and hope for the best</p>



<p class="wp-block-paragraph">but imagine if you uh if you try to write a huge long string in uh using system write call code one</p>



<p class="wp-block-paragraph">and maybe some of the characters did write but the system decided to only write i don&#8217;t know half for</p>



<p class="wp-block-paragraph">reason maybe it ran out of buffer maybe you know it interrupted you know your right or something</p>



<p class="wp-block-paragraph">like that so it could happen what that would mean is that the return value it would be greater than</p>



<p class="wp-block-paragraph">zero indicating that some characters were written but it&#8217;ll tell you exactly how many characters</p>



<p class="wp-block-paragraph">were written so you&#8217;ll know that you got to keep calling the sys call until all the characters were</p>



<p class="wp-block-paragraph">successfully written why would you do this i don&#8217;t know maybe you have a gigantic string like maybe</p>



<p class="wp-block-paragraph">like a several gigabyte file and you wanted to copy it to another file so you&#8217;ll be calling</p>



<p class="wp-block-paragraph">system write over and over again and system write it&#8217;s only going to write so many bytes at the same</p>



<p class="wp-block-paragraph">time so you use the return value to figure out how far forward in the read buffer you need to advance</p>



<p class="wp-block-paragraph">or you know whatever so that you can well write the entire complete file or the entire complete</p>



<p class="wp-block-paragraph">string or whatever it is without any gaps without it being truncated and so forth and then of course</p>



<p class="wp-block-paragraph">And then of course, if it returns a negative value, then it totally failed.</p>



<p class="wp-block-paragraph">Like you tried to write to a bad file handle, like standard input or a file handle that</p>



<p class="wp-block-paragraph">was closed or a file handle that was open for reading only, something like that.</p>



<p class="wp-block-paragraph">And then you can use some if else, you know, branching logic.</p>



<p class="wp-block-paragraph">I mean, not if else in assembly, it&#8217;s just going to be comparison and conditional jumping</p>



<p class="wp-block-paragraph">or branching.</p>



<p class="wp-block-paragraph">But you can have more control over your program, right?</p>



<p class="wp-block-paragraph">Because you want your program to be able to respond to errors.</p>



<p class="wp-block-paragraph">Let me just quickly cruise through all of the other options and let you know that</p>



<p class="wp-block-paragraph">and let you know that in another video I&#8217;m gonna do a full tutorial for how to</p>



<p class="wp-block-paragraph">copy one file to another by opening one file for reading and then like using</p>



<p class="wp-block-paragraph">system calls to read from it and then open another file for writing and then</p>



<p class="wp-block-paragraph">you know use system calls to write to it and I&#8217;m gonna do that looping buffer</p>



<p class="wp-block-paragraph">stuff that I talked about before anyway so but for now I&#8217;m just gonna go through</p>



<p class="wp-block-paragraph">the rest of these system call codes let&#8217;s see so first off we got open well</p>



<p class="wp-block-paragraph">Well, if you want to open a file, then you just give it call code 2 and you pass in the</p>



<p class="wp-block-paragraph">address here, you know, RDI, you say, here&#8217;s the address of a null terminated file name.</p>



<p class="wp-block-paragraph">So that means somewhere in memory, you have to have the file name that you want to open</p>



<p class="wp-block-paragraph">with a null terminator, like a zero at the end of the string, either the full path or</p>



<p class="wp-block-paragraph">relative path to wherever the program is currently running.</p>



<p class="wp-block-paragraph">And then RSI is going to be file status flags.</p>



<p class="wp-block-paragraph">And what does that mean?</p>



<p class="wp-block-paragraph">And what does that mean? We can actually just search for that.</p>



<p class="wp-block-paragraph">I&#8217;m going to say control C to copy,</p>



<p class="wp-block-paragraph">and then I&#8217;m going to do control F to search for that.</p>



<p class="wp-block-paragraph">And let&#8217;s see what page of mine right now, 340.</p>



<p class="wp-block-paragraph">If I go down to the search results for that,</p>



<p class="wp-block-paragraph">it just explains what the file modes are. So if you put value zero,</p>



<p class="wp-block-paragraph">that means read only you&#8217;re opening the file and read only mode value one.</p>



<p class="wp-block-paragraph">That means a write only a value to allows reading and writing to the file.</p>



<p class="wp-block-paragraph">So if you don&#8217;t know what that means, well, there it was.</p>



<p class="wp-block-paragraph">What was I just on before?</p>



<p class="wp-block-paragraph">40?</p>



<p class="wp-block-paragraph">Oh, gosh.</p>



<p class="wp-block-paragraph">Completely lost my…</p>



<p class="wp-block-paragraph">Oh, yeah, 40.</p>



<p class="wp-block-paragraph">Okay, so opening pretty easy, right?</p>



<p class="wp-block-paragraph">Like if you didn&#8217;t know this before, you didn&#8217;t necessarily read me.</p>



<p class="wp-block-paragraph">You could just look at this table and go, what do I want to do?</p>



<p class="wp-block-paragraph">I want to open.</p>



<p class="wp-block-paragraph">So here&#8217;s the code.</p>



<p class="wp-block-paragraph">Here&#8217;s the address that it needs.</p>



<p class="wp-block-paragraph">When you&#8217;re done opening a file, when you&#8217;re done working with a file,</p>



<p class="wp-block-paragraph">you want to close that file unless the whole program is going to terminate.</p>



<p class="wp-block-paragraph">unless the whole program is going to terminate at that point you i mean maybe you have a function</p>



<p class="wp-block-paragraph">that gets called somewhat often and you kind of always have to open a file and sort of look at</p>



<p class="wp-block-paragraph">something or write something and maybe you want to close it when the function is over right you</p>



<p class="wp-block-paragraph">don&#8217;t want to have a file handle just open forever that&#8217;s a waste of memory and it might introduce</p>



<p class="wp-block-paragraph">bad behavior to your program if you just have a bunch of file handles floating around that you</p>



<p class="wp-block-paragraph">forgot about so it&#8217;s proper to close a file when you&#8217;re finished with it that&#8217;s just going to be</p>



<p class="wp-block-paragraph">and it only wants one argument.</p>



<p class="wp-block-paragraph">It just wants the file descriptor of the file that you wanted to close.</p>



<p class="wp-block-paragraph">So if you open a file for a reading or to create it,</p>



<p class="wp-block-paragraph">you get a file descriptor back.</p>



<p class="wp-block-paragraph">You should probably hang on to it somewhere on the stack</p>



<p class="wp-block-paragraph">or like in a global variable or like, you know, in a register or whatever.</p>



<p class="wp-block-paragraph">Then when you&#8217;re done doing something to that file</p>



<p class="wp-block-paragraph">and you&#8217;re sure that it&#8217;s time to close it,</p>



<p class="wp-block-paragraph">just give that handle right back when you call code three to close it.</p>



<p class="wp-block-paragraph">Then you can sort of like seek, you know,</p>



<p class="wp-block-paragraph">forward and backwards to the file if you want to.</p>



<p class="wp-block-paragraph">You can fork the current process.</p>



<p class="wp-block-paragraph">You can fork the current process that&#8217;s kind of advanced for this video.</p>



<p class="wp-block-paragraph">You can exit.</p>



<p class="wp-block-paragraph">Remember before we exited from that program with code 60.</p>



<p class="wp-block-paragraph">So that&#8217;s it. Call code 60.</p>



<p class="wp-block-paragraph">If you didn&#8217;t watch this video, you could have gone through this table and just said,</p>



<p class="wp-block-paragraph">Oh, you know, I want to terminate the executing process.</p>



<p class="wp-block-paragraph">I do a system call with code 60 and I&#8217;ll give the exit status to RDI,</p>



<p class="wp-block-paragraph">which is typically zero for success.</p>



<p class="wp-block-paragraph">Bunch of other stuffs create, get the time of day,</p>



<p class="wp-block-paragraph">and then the file modes that we talked about before.</p>



<p class="wp-block-paragraph">we talked about before and then file permissions. Let&#8217;s see, where&#8217;s the permission. I think it&#8217;s</p>



<p class="wp-block-paragraph">when you want to create a file. Yeah, right here. If we wanted to create a file, that&#8217;s code 85.</p>



<p class="wp-block-paragraph">RDI is the name of the file, you know, like a pointer to the string. RSI is the file mode flags.</p>



<p class="wp-block-paragraph">And then you&#8217;re thinking like, what are the file mode flags? Just go down here and then here you</p>



<p class="wp-block-paragraph">go. All the file modes that you could ever want. You just look at it and go, well, I guess I can</p>



<p class="wp-block-paragraph">I guess I can just copy paste this number right here and it&#8217;ll end up being, you know,</p>



<p class="wp-block-paragraph">whatever is described on the left and the right.</p>



<p class="wp-block-paragraph">Like the group has read, write and execute permissions and so forth.</p>



<p class="wp-block-paragraph">I mean, really, if you look at this long enough, you&#8217;ll kind of realize that this is a quad</p>



<p class="wp-block-paragraph">word because it has a Q on the end of it.</p>



<p class="wp-block-paragraph">And the rest is just an octal file permissions notation where this first number here, notice</p>



<p class="wp-block-paragraph">how the first two are zeros, but this first actual number here is something that applies</p>



<p class="wp-block-paragraph">to the user and then the next one applies to the group the next one applies to others who are not</p>



<p class="wp-block-paragraph">part of the user or group and this video is not about file permissions I&#8217;ll probably make one</p>



<p class="wp-block-paragraph">later if I think people will actually watch it but yeah you can just kind of like look it up here if</p>



<p class="wp-block-paragraph">you want to and just copy paste that into a define somewhere let&#8217;s see what else I just want to show</p>



<p class="wp-block-paragraph">you a little code snip just to illustrate a little bit more what I was talking about before</p>



<p class="wp-block-paragraph">for. People usually make this mistake, they&#8217;ll do see this is what people will usually do like new</p>



<p class="wp-block-paragraph">programmers. Suppose this is a function pretend we&#8217;re in C or C++. For the time being, you call</p>



<p class="wp-block-paragraph">some sort of a system function or an API of some other library. And you just you just hope that it</p>



<p class="wp-block-paragraph">works, you just call it and then your program continues underneath, right? It&#8217;s a bad idea,</p>



<p class="wp-block-paragraph">because maybe that failed, maybe there&#8217;s some action you need to take. So instead, it&#8217;s a really</p>



<p class="wp-block-paragraph">really good idea to check the return result or i should say an even better idea is check the</p>



<p class="wp-block-paragraph">documentation usually these types of you know c system calls or function calls or api calls or</p>



<p class="wp-block-paragraph">whatever they&#8217;ll return something indicating success or failure sometimes the documentation</p>



<p class="wp-block-paragraph">will tell you oh you&#8217;ve got to put like a pointer to some other data structure in the arguments</p>



<p class="wp-block-paragraph">and then the result comes there of course just read the documentation but usually it&#8217;s just</p>



<p class="wp-block-paragraph">So you want to grab the result and then check the result.</p>



<p class="wp-block-paragraph">In this case I&#8217;m assuming this is sort of a standard function that will return zero</p>



<p class="wp-block-paragraph">or greater on success like the system write call or the system read call and return less</p>



<p class="wp-block-paragraph">than zero if it fails.</p>



<p class="wp-block-paragraph">So here I&#8217;m just responding, you know, if it&#8217;s like if the result was greater than zero</p>



<p class="wp-block-paragraph">then it&#8217;s like, yay we can proceed.</p>



<p class="wp-block-paragraph">Maybe I&#8217;ll continue with my program in some way and if it&#8217;s not then I&#8217;ll print a complaint</p>



<p class="wp-block-paragraph">then I&#8217;ll print a complaint to the user and then I&#8217;ll take some sort of an action</p>



<p class="wp-block-paragraph">like I&#8217;ll write to a log file, send an email somewhere, you know,</p>



<p class="wp-block-paragraph">do something to try and recover from the error and alert admins to the error.</p>



<p class="wp-block-paragraph">And in this case, I&#8217;m just throwing an exception.</p>



<p class="wp-block-paragraph">This video is not about exceptions, but so I just want you to know,</p>



<p class="wp-block-paragraph">this is a good design pattern to not just discard the result of a call to</p>



<p class="wp-block-paragraph">something. You should check the result and see what you&#8217;re supposed to do.</p>



<p class="wp-block-paragraph">Let&#8217;s see, what else did I want to tip?</p>



<p class="wp-block-paragraph">system services, file handles.</p>



<p class="wp-block-paragraph">Yeah, okay, I think that&#8217;s everything that I wanted to tell you.</p>



<p class="wp-block-paragraph">In future videos, I&#8217;m going to talk about, you know, some of this stuff much more in-depth,</p>



<p class="wp-block-paragraph">like with my file.io video that I&#8217;m going to publish pretty soon, which is, you know,</p>



<p class="wp-block-paragraph">it lets you read and write to files, and it uses a loop to read a little bit at a time.</p>



<p class="wp-block-paragraph">Okay, thank you so much for watching this video.</p>



<p class="wp-block-paragraph">I hope you learned a little bit of stuff and had a little bit of fun.</p>



<p class="wp-block-paragraph">I&#8217;m outie.</p>



<p class="wp-block-paragraph">Or something.</p>



<p class="wp-block-paragraph">Goodbye.</p>



<p class="wp-block-paragraph">you&#8217;re looking at right now it would really mean the world to me and it&#8217;ll</p>



<p class="wp-block-paragraph">help make more videos and grow this community so we&#8217;ll be able to do more</p>



<p class="wp-block-paragraph">videos longer videos better videos or just I&#8217;ll be able to keep making videos</p>



<p class="wp-block-paragraph">in general so please do do me a kindness and and subscribe you know sometimes</p>



<p class="wp-block-paragraph">I&#8217;m sleeping in the middle of the night and I just wake up because I know</p>



<p class="wp-block-paragraph">somebody subscribed or followed it just wakes me up and I get filled with joy</p>



<p class="wp-block-paragraph">that&#8217;s exactly what happens every single time so you could do it as a nice favor</p>



<p class="wp-block-paragraph">could you control me if you want to just wake me up in the middle of the night</p>



<p class="wp-block-paragraph">just subscribe and then I&#8217;ll just wake up I promise that&#8217;s what will happen</p>



<p class="wp-block-paragraph">also if you look at the middle of the screen right now you should see a QR</p>



<p class="wp-block-paragraph">code which you can scan in order to go to the website which I think is also</p>



<p class="wp-block-paragraph">named somewhere at the bottom of this video and it&#8217;ll take you to my main</p>



<p class="wp-block-paragraph">website where you can just kind of like see all the videos I published and the</p>



<p class="wp-block-paragraph">services and tutorials and things that I offer and all that good stuff and if</p>



<p class="wp-block-paragraph">if you have a suggestion for uh uh clarifications or errata or just future videos that you want to</p>



<p class="wp-block-paragraph">see please leave a comment or if you just want to say hey what&#8217;s up what&#8217;s going on you know just</p>



<p class="wp-block-paragraph">send me a comment whatever i also wake up for those in the middle of the night i get i wake</p>



<p class="wp-block-paragraph">up in a cold sweat and i&#8217;m like it would really it really mean the world to me i would really</p>



<p class="wp-block-paragraph">appreciate it so again thank you so much for watching this video and um enjoy the cool music</p>



<p class="wp-block-paragraph">as I fade into the darkness which is coming for us all.</p>



<p class="wp-block-paragraph">Thank you.</p>
<p>The post <a href="https://www.NeuralLantern.com/mastering-system-services-in-x86-64-assembly-programming/">Mastering System Services in x86-64 Assembly Programming</a> appeared first on <a href="https://www.NeuralLantern.com">NeuralLantern.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.NeuralLantern.com/mastering-system-services-in-x86-64-assembly-programming/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Master Debugging with xxd: Inspect Program Output at a Byte Level for Automation &#038; Clean Code!</title>
		<link>https://www.NeuralLantern.com/master-debugging-with-xxd-inspect-program-output-at-a-byte-level-for-automation-clean-code/</link>
					<comments>https://www.NeuralLantern.com/master-debugging-with-xxd-inspect-program-output-at-a-byte-level-for-automation-clean-code/#respond</comments>
		
		<dc:creator><![CDATA[mike]]></dc:creator>
		<pubDate>Mon, 23 Jun 2025 02:41:27 +0000</pubDate>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Debugging]]></category>
		<category><![CDATA[Videos]]></category>
		<category><![CDATA[assembly programming]]></category>
		<category><![CDATA[automation debugging]]></category>
		<category><![CDATA[binary file inspection]]></category>
		<category><![CDATA[byte level debugging]]></category>
		<category><![CDATA[clean code]]></category>
		<category><![CDATA[coding tips]]></category>
		<category><![CDATA[coding tutorial]]></category>
		<category><![CDATA[debugging]]></category>
		<category><![CDATA[linux tools]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[programming errors]]></category>
		<category><![CDATA[software development]]></category>
		<category><![CDATA[terminal commands]]></category>
		<category><![CDATA[text file debugging]]></category>
		<category><![CDATA[xxd]]></category>
		<guid isPermaLink="false">https://www.NeuralLantern.com/?p=165</guid>

					<description><![CDATA[<p>Debug program output with xxd! Learn to inspect text/binary files at byte level, fix hidden issues, and ensure clean code. Perfect for automation &#038; assignments.</p>
<p>The post <a href="https://www.NeuralLantern.com/master-debugging-with-xxd-inspect-program-output-at-a-byte-level-for-automation-clean-code/">Master Debugging with xxd: Inspect Program Output at a Byte Level for Automation &amp; Clean Code!</a> appeared first on <a href="https://www.NeuralLantern.com">NeuralLantern.com</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<figure class="wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
<iframe loading="lazy" title="Master Debugging with xxd: Inspect Program Output at a Byte Level for Automation &amp; Clean Code!" width="1380" height="776" src="https://www.youtube.com/embed/UyE5t01Vnd0?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
</div></figure>



<p class="wp-block-paragraph">Hey coders, ever wonder why your program’s acting funky? Join me to master debugging with xxd! This vid walks you through inspecting text or binary file output at the byte level, catching sneaky characters like null bytes that mess up automation or school assignments. From assembly to redirects, learn practical tips to ensure clean output. Perfect for beginners and pros alike! Hit subscribe for more coding tutorials, and check my site for extra goodies. Let’s debug smarter, not harder!</p>



<p class="wp-block-paragraph">Introduction to xxd 00:00:00<br>Purpose of debugging 00:00:12<br>Why debug output 00:00:23<br>Example assembly program 00:00:56<br>Running the program 00:01:26<br>Corrupting the message 00:01:45<br>Terminal vs automation 00:02:27<br>Installing xxd 00:03:16<br>Redirecting output 00:03:29<br>Using xxd to debug 00:04:33<br>Identifying newline issue 00:05:36<br>Finding zero in string 00:06:04<br>Debugging conclusion 00:06:32<br>Weird symbols warning 00:06:47<br>Debugging standard error 00:07:23<br>Closing remarks 00:07:40<br>Call to subscribe 00:07:56<br>QR code and website 00:08:45<br>Request for comments 00:09:09<br>Fade out 00:09:31</p>



<p class="wp-block-paragraph">Thanks for watching!</p>



<p class="wp-block-paragraph">Find us on other social media here:</p>



<ul class="wp-block-list">
<li>https://www.NeuralLantern.com/social</li>
</ul>



<p class="wp-block-paragraph">Please help support us!</p>



<ul class="wp-block-list">
<li>Subscribing + Sharing on Social Media</li>



<li>Leaving a comment or suggestion</li>



<li>Subscribing to our Blog</li>



<li>Watching the main &#8220;pinned&#8221; video of this channel for offers and extras</li>
</ul>



<p class="wp-block-paragraph">Hey there, I&#8217;d like to talk to you about debugging your program&#8217;s output with xxd.</p>



<p class="wp-block-paragraph">What am I talking about? Well, there&#8217;s a program called xxd that can sort of inspect</p>



<p class="wp-block-paragraph">at the byte level the output of some text file or binary file. It&#8217;s really useful for</p>



<p class="wp-block-paragraph">inspecting things. Why would you want to debug the output of your program? Well, I don&#8217;t know.</p>



<p class="wp-block-paragraph">print a message from your program the program might be printing some extra characters somewhere</p>



<p class="wp-block-paragraph">or some garbage and maybe maybe you don&#8217;t notice because you&#8217;re sort of looking at your program&#8217;s</p>



<p class="wp-block-paragraph">output in the terminal but then maybe if your output is being sent to another program</p>



<p class="wp-block-paragraph">for the purposes of automation or like you&#8217;re getting a grade from a class or something like</p>



<p class="wp-block-paragraph">that then um well it can it can sort of it can sort of get you without you realizing what&#8217;s wrong</p>



<p class="wp-block-paragraph">you an example real fast of what i&#8217;m talking about i have a simple assembly program here this is not</p>



<p class="wp-block-paragraph">a video about how to write assembly code so just assume that you know if you want to know assembly</p>



<p class="wp-block-paragraph">see my other videos but um i&#8217;m just going to print a simple message i&#8217;m just going to print</p>



<p class="wp-block-paragraph">hello i feel awesome and then the length of the message i&#8217;m specifying here you don&#8217;t know you</p>



<p class="wp-block-paragraph">don&#8217;t need to know too much about this for this particular video i&#8217;m just printing a string in</p>



<p class="wp-block-paragraph">assembly that&#8217;s all i&#8217;m doing and then here you can see i&#8217;m just kind of like printing it and then</p>



<p class="wp-block-paragraph">I&#8217;m just kind of like printing it and then I&#8217;m like exiting.</p>



<p class="wp-block-paragraph">So if we go back to the terminal here, I can type make run.</p>



<p class="wp-block-paragraph">This is not a make file video.</p>



<p class="wp-block-paragraph">See my other videos.</p>



<p class="wp-block-paragraph">I want to type make run just to compile and run the program.</p>



<p class="wp-block-paragraph">And then here&#8217;s the message that it prints, right?</p>



<p class="wp-block-paragraph">Hello, I feel awesome.</p>



<p class="wp-block-paragraph">It looks good in the terminal.</p>



<p class="wp-block-paragraph">I can&#8217;t be 100% sure though, because think about this.</p>



<p class="wp-block-paragraph">What if I corrupted the message on purpose?</p>



<p class="wp-block-paragraph">This can happen in assembly all the time.</p>



<p class="wp-block-paragraph">Wrong or if you add extra characters at the end of it or even if you have you know a corrupted register somewhere</p>



<p class="wp-block-paragraph">That either reads from the wrong spot</p>



<p class="wp-block-paragraph">To get a string or maybe it it writes over the string for some reason. There&#8217;s a lot of things that can go wrong</p>



<p class="wp-block-paragraph">So for now just suppose that I&#8217;ve corrupted my message somehow by I don&#8217;t know. Let&#8217;s put a zero</p>



<p class="wp-block-paragraph">In between the string so I&#8217;m gonna say is that it&#8217;s gonna be like H E L</p>



<p class="wp-block-paragraph">0 L O and what that should do is</p>



<p class="wp-block-paragraph">lo and what that should do uh well it should look like just the word hello but if i&#8217;m automating</p>



<p class="wp-block-paragraph">this program or sending it in to get a grade at a school somewhere then this should you know not</p>



<p class="wp-block-paragraph">match what is expected if i&#8217;m automating with like another system in some way but it should look okay</p>



<p class="wp-block-paragraph">in the terminal let&#8217;s see i&#8217;m going to do clear and make run notice how the message looks the same</p>



<p class="wp-block-paragraph">I feel awesome. So if I was automating, you know, if I was sending this string to another program</p>



<p class="wp-block-paragraph">for automation, I might be convinced that I&#8217;m not doing anything wrong. And I&#8217;ll, I&#8217;ll think it&#8217;s</p>



<p class="wp-block-paragraph">the other side that is wrong or, or our computers are just buggy or something like that. But actually</p>



<p class="wp-block-paragraph">I&#8217;ve outputted a corrupted message for some reason. So how can I really be sure that my</p>



<p class="wp-block-paragraph">message is what I think I&#8217;m seeing in the terminal? That&#8217;s the XXD program. Pretty easy.</p>



<p class="wp-block-paragraph">apt install xxd let me see if I have it on this system oh it&#8217;s already installed</p>



<p class="wp-block-paragraph">okay good so I&#8217;m gonna do clear and make run again so there it is I would like to</p>



<p class="wp-block-paragraph">just redirect the standard output pipe to a file with a special command in the</p>



<p class="wp-block-paragraph">shell let me just show you real fast I am definitely printing to std out the</p>



<p class="wp-block-paragraph">standard pipe which is just a number one file descriptor if you don&#8217;t understand</p>



<p class="wp-block-paragraph">If you don&#8217;t understand that, I have other videos, but I&#8217;m going to run the program again,</p>



<p class="wp-block-paragraph">but then I&#8217;m going to redirect the output to a file and I&#8217;m going to call it stdout.txt.</p>



<p class="wp-block-paragraph">It&#8217;s probably a good idea to eliminate spaces.</p>



<p class="wp-block-paragraph">I think I&#8217;ve made mistakes in other videos where I didn&#8217;t put a space before or after</p>



<p class="wp-block-paragraph">this little redirector symbol and I ended up creating a file just called the number</p>



<p class="wp-block-paragraph">two or the number one.</p>



<p class="wp-block-paragraph">But pipe number one is standard output.</p>



<p class="wp-block-paragraph">So I&#8217;m going to say anything that comes to pipe one, which is standard output, I&#8217;m just</p>



<p class="wp-block-paragraph">output I&#8217;m just going to redirect it to a text file. So when I hit enter notice</p>



<p class="wp-block-paragraph">how nothing prints to the screen but the standard output text file that I</p>



<p class="wp-block-paragraph">specified is now created. If I spill the contents of std out it still looks</p>



<p class="wp-block-paragraph">normal so don&#8217;t let that trick you but watch what happens if I use xxd.</p>



<p class="wp-block-paragraph">xxd std out basically xxd is going to read it as a binary file and tell me</p>



<p class="wp-block-paragraph">every single character in there while I oh I forgot to change the title of that</p>



<p class="wp-block-paragraph">that&#8217;s not this video but notice right here where it says H E L L O and then</p>



<p class="wp-block-paragraph">right before that there&#8217;s like a little dot if you look at the dot let&#8217;s see</p>



<p class="wp-block-paragraph">what is the dot it&#8217;s one two three four five six it&#8217;s the sixth thing one two</p>



<p class="wp-block-paragraph">one two three four five six seven eight nine ten twelve thirteen fourteen fifteen oh there&#8217;s</p>



<p class="wp-block-paragraph">fifteen characters but there&#8217;s not that many i think probably they&#8217;re packing them by two here</p>



<p class="wp-block-paragraph">let me see if that makes more sense now one two three four five six one two three four five six</p>



<p class="wp-block-paragraph">yeah that makes a lot more sense so the sixth uh byte not the sixth uh word uh is basically</p>



<p class="wp-block-paragraph">to this dot right here and if you recall oa is a decimal 10 which is uh the beginning of a new line</p>



<p class="wp-block-paragraph">you know like a carriage return line feed um 13 comma 10 so that&#8217;s what it is right there</p>



<p class="wp-block-paragraph">and then so now we know that there&#8217;s xxd is figuring out here or helping us understand</p>



<p class="wp-block-paragraph">that there&#8217;s a new line between slash main and then the message which if you recall that&#8217;s</p>



<p class="wp-block-paragraph">exactly what happened and then when we look into our hello string there&#8217;s a dot in the middle here</p>



<p class="wp-block-paragraph">string there&#8217;s a dot in the middle here what is that dot well we just have to figure out what</p>



<p class="wp-block-paragraph">number that corresponds to so the oa was that dot right there so we just got to go a couple more</p>



<p class="wp-block-paragraph">bytes forward one two three four bytes forward one two three four bytes forward it&#8217;s this zero right</p>



<p class="wp-block-paragraph">so xxd even though the terminal didn&#8217;t help us originally xxd has helped us realize that we&#8217;re</p>



<p class="wp-block-paragraph">that we&#8217;re actually printing a zero under the hood and we can&#8217;t see it in the terminal.</p>



<p class="wp-block-paragraph">So we have now debugged our output. You know, depending on where you print this,</p>



<p class="wp-block-paragraph">you might see nothing like in the terminal. It didn&#8217;t really show anything. But if you&#8217;re on a</p>



<p class="wp-block-paragraph">webpage somewhere or some other type of thing that&#8217;s going to print the data for you, you might</p>



<p class="wp-block-paragraph">see a weird symbol. I mean, it really depends. This is not something you&#8217;ll see everywhere, but</p>



<p class="wp-block-paragraph">you might see a weird symbol that kind of looks like a black diamond with a question mark inside</p>



<p class="wp-block-paragraph">mark inside of it or some other weird symbol.</p>



<p class="wp-block-paragraph">If you start seeing weird symbols all over the place or just in a place where you know</p>



<p class="wp-block-paragraph">there&#8217;s not supposed to be a weird symbol, that might be an indication to you that you</p>



<p class="wp-block-paragraph">have weird values sitting inside of your string.</p>



<p class="wp-block-paragraph">And then you should probably try to debug with XXD.</p>



<p class="wp-block-paragraph">So that&#8217;s it.</p>



<p class="wp-block-paragraph">That&#8217;s the basics for debugging with XXD.</p>



<p class="wp-block-paragraph">Just, you know, file output anyway, for your information.</p>



<p class="wp-block-paragraph">If you wanted to debug the standard error pipe, you could also do this.</p>



<p class="wp-block-paragraph">you know because the error pipe is just a two um and that&#8217;s basically it i&#8217;m not going to</p>



<p class="wp-block-paragraph">debug right now because that&#8217;s that&#8217;s too easy but i hope you enjoyed this video thank you for</p>



<p class="wp-block-paragraph">watching i hope you learned a little bit and had a little bit of fun i&#8217;ll see you in the next video</p>



<p class="wp-block-paragraph">hey everybody thanks for watching this video again from the bottom of my heart i really</p>



<p class="wp-block-paragraph">appreciate it i do hope you did learn something and have some fun uh if you could do me a please</p>



<p class="wp-block-paragraph">If you could do me a please, a small little favor, could you please subscribe and follow this channel or these videos or whatever it is you do on the current social media website that you&#8217;re looking at right now.</p>



<p class="wp-block-paragraph">It would really mean the world to me and it&#8217;ll help make more videos and grow this community.</p>



<p class="wp-block-paragraph">So we&#8217;ll be able to do more videos, longer videos, better videos, or just I&#8217;ll be able to keep making videos in general.</p>



<p class="wp-block-paragraph">So please do me a kindness and subscribe.</p>



<p class="wp-block-paragraph">the middle of the night and i just wake up because i know somebody subscribed or followed</p>



<p class="wp-block-paragraph">it just wakes me up and i get filled with joy that&#8217;s exactly what happens every single time</p>



<p class="wp-block-paragraph">so you could do it as a nice favor to me or you could you could troll me if you want to just wake</p>



<p class="wp-block-paragraph">me up in the middle of the night just subscribe and then i&#8217;ll i&#8217;ll just wake up i promise that&#8217;s</p>



<p class="wp-block-paragraph">what will happen also uh if you look at the middle of the screen right now you should see a qr code</p>



<p class="wp-block-paragraph">which you can scan in order to go to the website which i think is also named somewhere at the</p>



<p class="wp-block-paragraph">you to my main website where you can just kind of like see all the videos I published and the</p>



<p class="wp-block-paragraph">services and tutorials and things that I offer and all that good stuff and uh if you have a</p>



<p class="wp-block-paragraph">suggestion for uh uh clarifications or errata or just future videos that you want to see please</p>



<p class="wp-block-paragraph">leave a comment or if you just want to say hey what&#8217;s up what&#8217;s going on you know just send me</p>



<p class="wp-block-paragraph">a comment whatever I also wake up for those in the middle of the night I get I wake up in a cold</p>



<p class="wp-block-paragraph">it would really mean the world to me. I would really appreciate it. So again,</p>



<p class="wp-block-paragraph">thank you so much for watching this video and enjoy the cool music as I fade</p>



<p class="wp-block-paragraph">into the darkness, which is coming for us all.</p>



<p class="wp-block-paragraph">Thank you.</p>
<p>The post <a href="https://www.NeuralLantern.com/master-debugging-with-xxd-inspect-program-output-at-a-byte-level-for-automation-clean-code/">Master Debugging with xxd: Inspect Program Output at a Byte Level for Automation &amp; Clean Code!</a> appeared first on <a href="https://www.NeuralLantern.com">NeuralLantern.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.NeuralLantern.com/master-debugging-with-xxd-inspect-program-output-at-a-byte-level-for-automation-clean-code/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Master GNU Debugger: Debug C++ &#038; Assembly Programs with GDB Like a Pro</title>
		<link>https://www.NeuralLantern.com/master-gnu-debugger-debug-c-assembly-programs-with-gdb-like-a-pro/</link>
					<comments>https://www.NeuralLantern.com/master-gnu-debugger-debug-c-assembly-programs-with-gdb-like-a-pro/#respond</comments>
		
		<dc:creator><![CDATA[mike]]></dc:creator>
		<pubDate>Sat, 14 Jun 2025 23:53:13 +0000</pubDate>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Debugging]]></category>
		<category><![CDATA[Videos]]></category>
		<category><![CDATA[assembly debugging]]></category>
		<category><![CDATA[assembly programming]]></category>
		<category><![CDATA[breakpoints]]></category>
		<category><![CDATA[c++ debugging]]></category>
		<category><![CDATA[C++ programming]]></category>
		<category><![CDATA[call stack]]></category>
		<category><![CDATA[coding for beginners]]></category>
		<category><![CDATA[coding tutorial]]></category>
		<category><![CDATA[debug symbols]]></category>
		<category><![CDATA[debugging tools]]></category>
		<category><![CDATA[GDB]]></category>
		<category><![CDATA[GNU Debugger]]></category>
		<category><![CDATA[null pointer]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[software development]]></category>
		<guid isPermaLink="false">https://www.NeuralLantern.com/?p=155</guid>

					<description><![CDATA[<p>Master GDB to debug C++ &#038; assembly! Learn breakpoints, call stacks, &#038; crash fixes in this fun guide for coders.</p>
<p>The post <a href="https://www.NeuralLantern.com/master-gnu-debugger-debug-c-assembly-programs-with-gdb-like-a-pro/">Master GNU Debugger: Debug C++ &amp; Assembly Programs with GDB Like a Pro</a> appeared first on <a href="https://www.NeuralLantern.com">NeuralLantern.com</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<figure class="wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
<iframe loading="lazy" title="Master GNU Debugger: Debug C++ &amp; Assembly Programs with GDB Like a Pro" width="1380" height="776" src="https://www.youtube.com/embed/lPcwsvSWak0?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
</div></figure>



<p class="wp-block-paragraph">Hey everybody! Ready to crush those pesky bugs in your C++ and assembly programs? In this video, we’re diving deep into the GNU Debugger (GDB) – the ultimate tool for tracking down crashes, inspecting variables, and mastering your code. From setting up debug symbols to navigating call stacks, setting breakpoints, and even debugging assembly registers, this fun and relatable guide has you covered. Whether you’re a beginner coder or a seasoned dev, you’ll learn practical tips to level up your debugging game. We’ll also tackle null pointers, create GDB scripts, and explore why your program might be misbehaving. Stick around for a few laughs and some serious skills! Don’t forget to subscribe, hit that like button, and check out my website for more coding tutorials. Let’s debug like pros together!</p>



<p class="wp-block-paragraph">Introduction to GNU Debugger 00:00:00<br>What is a Debugger 00:00:20<br>Debug Symbols Explanation 00:02:08<br>Compiling with Debug Symbols 00:03:13<br>File Size Comparison 00:05:30<br>Installing and Launching GDB 00:06:21<br>GDB Console Basics 00:06:55<br>Attaching GDB to Program 00:08:12<br>Running Program in GDB 00:09:09<br>Handling Program Crash 00:13:02<br>Understanding Call Stack 00:14:05<br>Navigating Call Stack 00:18:13<br>Inspecting Variables 00:19:08<br>Null Pointer Issues 00:21:25<br>Using GDB Script 00:25:10<br>Setting Breakpoints 00:27:04<br>Managing Breakpoints 00:28:37<br>Continuing Execution 00:30:41<br>Debugging Assembly 00:33:24<br>Global Variables in Assembly 00:35:43<br>Advanced GDB Commands 00:38:31<br>Conclusion and Call to Action 00:40:22</p>



<p class="wp-block-paragraph">Thanks for watching!</p>



<p class="wp-block-paragraph">Find us on other social media here:</p>



<ul class="wp-block-list">
<li>https://www.NeuralLantern.com/social</li>
</ul>



<p class="wp-block-paragraph">Please help support us!</p>



<ul class="wp-block-list">
<li>Subscribing + Sharing on Social Media</li>



<li>Leaving a comment or suggestion</li>



<li>Subscribing to our Blog</li>



<li>Watching the main &#8220;pinned&#8221; video of this channel for offers and extras</li>
</ul>



<p class="wp-block-paragraph">Hey everybody! In this video I&#8217;m going to show you how to use the GNU Debugger to</p>



<p class="wp-block-paragraph">debug your C++ and assembly programs.</p>



<p class="wp-block-paragraph">You can also use it for C and some other stuff but we&#8217;re just going to focus on</p>



<p class="wp-block-paragraph">C++ and assembly. What is the GNU Debugger and what is a debugger in the</p>



<p class="wp-block-paragraph">first place? So for starters the GNU Debugger it&#8217;s like it&#8217;s called GDB and</p>



<p class="wp-block-paragraph">the db you can imagine that stands for debugger something like that and the g stands for gnu i</p>



<p class="wp-block-paragraph">personally don&#8217;t know how to uh pronounce gnu so i just say gnu because it it feels more fun to do</p>



<p class="wp-block-paragraph">it that way it&#8217;s more interesting i think probably some people just say new but i don&#8217;t like that</p>



<p class="wp-block-paragraph">because the gdb debugger is really old and robust and powerful it&#8217;s not a new tool it&#8217;s it&#8217;s an old</p>



<p class="wp-block-paragraph">new debugger someone&#8217;s always going to ask what was the old debugger and then I say this is the</p>



<p class="wp-block-paragraph">old debugger the new debugger is the old debugger anyway so we&#8217;re going to use the GNU debugger</p>



<p class="wp-block-paragraph">if you haven&#8217;t yet watched my video on caveman debugging you probably want to watch that first</p>



<p class="wp-block-paragraph">just for like some basics of you know why you might want to look at information in your program</p>



<p class="wp-block-paragraph">but for now we&#8217;ll just assume that you already know what&#8217;s going on with just like why you would</p>



<p class="wp-block-paragraph">know how to make make files see my other videos but here i just have a basic make file all it&#8217;s</p>



<p class="wp-block-paragraph">really going to do is just sort of compile a very simple program and add debug symbols into it so</p>



<p class="wp-block-paragraph">let&#8217;s double check that i&#8217;m actually doing that here yeah there we go okay so the first thing</p>



<p class="wp-block-paragraph">that i should probably show you is uh we are compiling a c plus plus source module so i&#8217;ve</p>



<p class="wp-block-paragraph">actually using c but i i have that left over in there anyway and then we&#8217;re assembling something</p>



<p class="wp-block-paragraph">in yasm we&#8217;re linking with g plus plus because we want to have a hybrid program and we&#8217;ve got</p>



<p class="wp-block-paragraph">all these flags here those are just variables and so uh so now before i can debug with gdb</p>



<p class="wp-block-paragraph">i&#8217;ve got to talk about something called debug symbols what are debug symbols imagine just a</p>



<p class="wp-block-paragraph">bunch of extra information explaining all of the design and variables and everything inside of your</p>



<p class="wp-block-paragraph">about your code stuffed directly into the executable.</p>



<p class="wp-block-paragraph">So imagine, you know, when we compile a C++ source module</p>



<p class="wp-block-paragraph">into an object file, usually that&#8217;s just, you know,</p>



<p class="wp-block-paragraph">assembly at that point.</p>



<p class="wp-block-paragraph">But when we add debug symbols, we&#8217;ll have a bunch of information</p>



<p class="wp-block-paragraph">that can help the debugger figure out where we are in the program,</p>



<p class="wp-block-paragraph">what the variables look like, you know,</p>



<p class="wp-block-paragraph">a bunch of extra information to help the debugger pretty much.</p>



<p class="wp-block-paragraph">The assembler will put debug symbols into the object code</p>



<p class="wp-block-paragraph">symbols into the object code that you generate the compilers will do that the linker will do that</p>



<p class="wp-block-paragraph">and so it&#8217;s important to understand if you don&#8217;t generate debug symbols when you&#8217;re compiling and</p>



<p class="wp-block-paragraph">linking your code then your debugger won&#8217;t actually be able to do anything it won&#8217;t understand what&#8217;s</p>



<p class="wp-block-paragraph">going on you can debug it but like you&#8217;re not going to see anything that&#8217;s very uh that&#8217;s useful</p>



<p class="wp-block-paragraph">so let me show you real fast i&#8217;m going to do make clean and then i&#8217;m going to say make build</p>



<p class="wp-block-paragraph">that I do not have debug symbols.</p>



<p class="wp-block-paragraph">All right, okay, if you don&#8217;t know how to compile and link from the command line, see</p>



<p class="wp-block-paragraph">my other videos, but for now it looks like we&#8217;re not generating debug symbols.</p>



<p class="wp-block-paragraph">So if I list the contents of my directory here, just note the size is real fast.</p>



<p class="wp-block-paragraph">I have an assembly module here that I&#8217;m calling ASI.asm, ASI for assembly, and then we&#8217;re</p>



<p class="wp-block-paragraph">assembling it down to an object file.</p>



<p class="wp-block-paragraph">Notice how it&#8217;s just 656 bytes, very small.</p>



<p class="wp-block-paragraph">plus plus module that I&#8217;m creating here is compiling to an object file that is</p>



<p class="wp-block-paragraph">about four and a half kilobytes so you know not too big the final executable is</p>



<p class="wp-block-paragraph">called main and it&#8217;s about 17 kilobytes so this is without debug symbols when</p>



<p class="wp-block-paragraph">you&#8217;re compiling something on your own you need to add extra switches to enable</p>



<p class="wp-block-paragraph">debug symbols so you can see here in this make file that I&#8217;ve made and again if</p>



<p class="wp-block-paragraph">you don&#8217;t know how to make a make file or compile or link or anything see my</p>



<p class="wp-block-paragraph">But for now, I&#8217;m just going to assume you kind of know your way around to makefile,</p>



<p class="wp-block-paragraph">or at least you can kind of infer what&#8217;s going on.</p>



<p class="wp-block-paragraph">So I&#8217;ve commented out a different version of this variable for the flags of my C++ compiler.</p>



<p class="wp-block-paragraph">If I uncomment this and then comment out the other one,</p>



<p class="wp-block-paragraph">you&#8217;ll notice the only real difference is this part right here, dash G dwarf 2.</p>



<p class="wp-block-paragraph">Usually in C++ compilation, it&#8217;ll just be dash G to generate debug symbols,</p>



<p class="wp-block-paragraph">and then the symbol format will default to a format called dwarf2 so I don&#8217;t know for these</p>



<p class="wp-block-paragraph">tutorials I like to just specify the full format but you can just say dash g in your c++ compiler</p>



<p class="wp-block-paragraph">and linker we do the same thing for the linker down here so I&#8217;m going to uncomment this</p>



<p class="wp-block-paragraph">and comment that and the only difference is just g dwarf2 so I&#8217;m just telling my linker that I also</p>



<p class="wp-block-paragraph">want debug symbols in there too then we do the same thing for the assembler so I&#8217;m going to</p>



<p class="wp-block-paragraph">So I&#8217;m going to uncomment that and comment this other one.</p>



<p class="wp-block-paragraph">And the only difference is that in the assembler,</p>



<p class="wp-block-paragraph">we kind of have to specify it a little bit differently.</p>



<p class="wp-block-paragraph">Instead of G dwarf dash two,</p>



<p class="wp-block-paragraph">it&#8217;s just G dwarf two as just one string.</p>



<p class="wp-block-paragraph">And I think with Yasm, you have to specify the debug symbol format.</p>



<p class="wp-block-paragraph">So just keep that in mind.</p>



<p class="wp-block-paragraph">So now I&#8217;ve turned on all the debug symbols.</p>



<p class="wp-block-paragraph">I&#8217;m going to do real fast, make clean and make build one more time.</p>



<p class="wp-block-paragraph">And then if I list everything,</p>



<p class="wp-block-paragraph">list everything let me just double check that it&#8217;s building the symbols now right okay good</p>



<p class="wp-block-paragraph">notice that the files are bigger so this asio um file is now 1.8 kilobytes instead of you know</p>



<p class="wp-block-paragraph">half a kilobyte the main.o object file is now 36 kilobytes instead of only 4.5 and the executable</p>



<p class="wp-block-paragraph">main is 36 kilobytes instead of just 17. so you can feel it already right like there&#8217;s a bunch</p>



<p class="wp-block-paragraph">extra information sitting inside the object files and the binary which allows us to debug our program</p>



<p class="wp-block-paragraph">okay so now that we&#8217;ve generated debug symbols in our program we can actually think about starting</p>



<p class="wp-block-paragraph">to use gdb so gdb is a program just gdb by the command line if you don&#8217;t have it in your system</p>



<p class="wp-block-paragraph">already you can go sudo apt install gdb or depending on what system you&#8217;re on maybe a or</p>



<p class="wp-block-paragraph">or whatever your package management program is,</p>



<p class="wp-block-paragraph">but we just need to install GDB.</p>



<p class="wp-block-paragraph">On Ubuntu and Debian, I think,</p>



<p class="wp-block-paragraph">there is a meta package called build essential,</p>



<p class="wp-block-paragraph">which will give you a bunch of compilation tools</p>



<p class="wp-block-paragraph">and make file stuff and whatever.</p>



<p class="wp-block-paragraph">So I&#8217;m just going to assume at this point</p>



<p class="wp-block-paragraph">you already have GDB on your system.</p>



<p class="wp-block-paragraph">To launch GDB and go into its console,</p>



<p class="wp-block-paragraph">just type GDB by itself.</p>



<p class="wp-block-paragraph">So now we&#8217;re inside of the GDB console or terminal.</p>



<p class="wp-block-paragraph">console or terminal. We&#8217;re no longer inside of a bash terminal. We can&#8217;t type normal commands.</p>



<p class="wp-block-paragraph">Let me show you real fast. Here&#8217;s the first command you want to learn on GDB. It&#8217;s called</p>



<p class="wp-block-paragraph">quit. Never quit. Never surrender. So, you know, normally if you&#8217;re at the command line,</p>



<p class="wp-block-paragraph">you can do something like cat, etc. OS release just to see what operating system you&#8217;re using.</p>



<p class="wp-block-paragraph">So you can see for this virtual machine that I&#8217;m using right now, I&#8217;ve got like Ubuntu 22 on there.</p>



<p class="wp-block-paragraph">If we go inside of GDB, we can&#8217;t use regular bash commands anymore or regular operating</p>



<p class="wp-block-paragraph">system commands.</p>



<p class="wp-block-paragraph">We can&#8217;t say cat, et cetera, OS release because we can now only use GDB commands.</p>



<p class="wp-block-paragraph">We&#8217;re inside of GDB already.</p>



<p class="wp-block-paragraph">Notice how it says undefined catch command.</p>



<p class="wp-block-paragraph">I don&#8217;t know what you&#8217;re talking about, dude.</p>



<p class="wp-block-paragraph">Okay.</p>



<p class="wp-block-paragraph">So remember we do a Q or quit to get out.</p>



<p class="wp-block-paragraph">You can actually just type Q.</p>



<p class="wp-block-paragraph">A lot of commands that I&#8217;m going to be talking about.</p>



<p class="wp-block-paragraph">going to be talking about you can abbreviate them with one or two or three letters and it totally</p>



<p class="wp-block-paragraph">works just for speed so now that we know how to enter gdb and now that we also know that we have</p>



<p class="wp-block-paragraph">already compiled our program with debug symbols we can attach gdb to our program i mean what&#8217;s the</p>



<p class="wp-block-paragraph">whole point of a debugger we most of the time we will just have our debugger attached to our program</p>



<p class="wp-block-paragraph">and launch it or i guess launch it while it&#8217;s attached you can also attach to a running program</p>



<p class="wp-block-paragraph">but we&#8217;re going to launch a program and stay attached to it.</p>



<p class="wp-block-paragraph">And then we can sort of catch crashes and see what&#8217;s going on.</p>



<p class="wp-block-paragraph">Or we could also tell the debugger to stop the program at certain points in time,</p>



<p class="wp-block-paragraph">like when we hit a certain line number or when a variable changes or something like that.</p>



<p class="wp-block-paragraph">And then we can look around.</p>



<p class="wp-block-paragraph">We can look at all the variables, look at the state of the program,</p>



<p class="wp-block-paragraph">even change things if we wanted to.</p>



<p class="wp-block-paragraph">We can look at all the registers if you&#8217;re coding in assembly.</p>



<p class="wp-block-paragraph">So it&#8217;s pretty useful.</p>



<p class="wp-block-paragraph">Anyway, I&#8217;m going to go gdb and the next command we&#8217;re going to learn is file, which just tells</p>



<p class="wp-block-paragraph">gdb to attach to a program so that we can run it.</p>



<p class="wp-block-paragraph">So, you know, the name of our program here that we compiled is just called main.</p>



<p class="wp-block-paragraph">And so if I type file main, then gdb should load up that file and try to parse its debug</p>



<p class="wp-block-paragraph">symbols so it can begin debugging for you.</p>



<p class="wp-block-paragraph">Notice how it says reading symbols from main.</p>



<p class="wp-block-paragraph">you know if we did a typo or we had something with no debug symbols it will give us some sort</p>



<p class="wp-block-paragraph">of an error message so for now i&#8217;m just going to quit and then go back in just to make sure that</p>



<p class="wp-block-paragraph">it&#8217;s all clean and we&#8217;re going to do file main now it attaches once it&#8217;s attached that&#8217;s not i guess</p>



<p class="wp-block-paragraph">it&#8217;s not technically attached because the program&#8217;s not running but once it has loaded the debug</p>



<p class="wp-block-paragraph">symbols for that program we can run the program with the run command in gdb also kind of interesting</p>



<p class="wp-block-paragraph">If you have debug symbols that are generated separately from your executable,</p>



<p class="wp-block-paragraph">you could tell GDB to load the symbols file and then run your program.</p>



<p class="wp-block-paragraph">That happens a lot in Linux where people release the non-debug friendly version of a program</p>



<p class="wp-block-paragraph">and then they&#8217;ll release the debug symbols separately if you&#8217;re interested.</p>



<p class="wp-block-paragraph">Anyway, so I&#8217;m going to type run and it&#8217;ll run the program.</p>



<p class="wp-block-paragraph">Notice how GDB kind of tells us that it&#8217;s starting up now.</p>



<p class="wp-block-paragraph">here&#8217;s like a thread debugger that&#8217;s being enabled and it says we&#8217;re using this library to do it and</p>



<p class="wp-block-paragraph">then it says hello you know here&#8217;s the hello message so the program is actually running that&#8217;s</p>



<p class="wp-block-paragraph">not my name i wish it was and then it prints the final result and then gdb says your program exited</p>



<p class="wp-block-paragraph">normally on newer versions of gdb there&#8217;s a setting i think by default where it&#8217;ll ask you</p>



<p class="wp-block-paragraph">if you want to start a debug daemon a debug info daemon or something yes or no you can usually just</p>



<p class="wp-block-paragraph">without actually having to type n.</p>



<p class="wp-block-paragraph">It&#8217;s a little bit faster.</p>



<p class="wp-block-paragraph">So the whole program ran and finished.</p>



<p class="wp-block-paragraph">If I type run again, it does the same thing.</p>



<p class="wp-block-paragraph">In GDB, if you hit enter without typing anything,</p>



<p class="wp-block-paragraph">it ends up repeating the previous command.</p>



<p class="wp-block-paragraph">So I&#8217;m not going to type run.</p>



<p class="wp-block-paragraph">If I just hit enter, are you serious?</p>



<p class="wp-block-paragraph">GDB made me into a liar.</p>



<p class="wp-block-paragraph">Well, most of the commands will repeat if you hit enter.</p>



<p class="wp-block-paragraph">I guess not the run command.</p>



<p class="wp-block-paragraph">So I&#8217;ll type run again.</p>



<p class="wp-block-paragraph">And okay, I mean, the program is pretty good, right?</p>



<p class="wp-block-paragraph">So if you watched my…</p>



<p class="wp-block-paragraph">It&#8217;s not pretty good.</p>



<p class="wp-block-paragraph">watched my it&#8217;s not pretty good it&#8217;s a nonsense program I mean it it doesn&#8217;t crash is what I&#8217;m</p>



<p class="wp-block-paragraph">saying if you watched my previous video which you should on caveman debugging I had this uh you know</p>



<p class="wp-block-paragraph">nonsense portion of code that just sort of updated a variable and we pretended that we were confused</p>



<p class="wp-block-paragraph">and we didn&#8217;t understand what was happening and uh we used gdb to debug it so what I&#8217;m going to do</p>



<p class="wp-block-paragraph">either let&#8217;s say we&#8217;ll start off with throwing an exception and then we&#8217;ll try to use a no pointer</p>



<p class="wp-block-paragraph">and then we&#8217;ll see a crash and then after that I&#8217;m going to start using breakpoints where we can stop</p>



<p class="wp-block-paragraph">automatically inside of our program to print the state of the program print the variables</p>



<p class="wp-block-paragraph">and then I&#8217;m going to do that first in C++ and then hopefully I&#8217;ll remember to do that in</p>



<p class="wp-block-paragraph">assembly right after it&#8217;s basically the same thing only with assembly you don&#8217;t really have</p>



<p class="wp-block-paragraph">you know a bunch of variables everywhere you just kind of have registers and maybe some globals</p>



<p class="wp-block-paragraph">globals but it&#8217;s going to be the same deal okay so let&#8217;s pretend that uh we are gonna have a crash</p>



<p class="wp-block-paragraph">okay so this program just kind of runs later on we&#8217;ll figure out why the result is wrong we&#8217;ll</p>



<p class="wp-block-paragraph">just pretend that it&#8217;s wrong but for now we&#8217;ll just say how about we uncomment this line right</p>



<p class="wp-block-paragraph">here and what will happen is when we&#8217;re running the main loop at some point in the loop we get</p>



<p class="wp-block-paragraph">When F gets called, the input will be looked at here.</p>



<p class="wp-block-paragraph">And if the input is more than one,</p>



<p class="wp-block-paragraph">which is definitely gonna happen like right away,</p>



<p class="wp-block-paragraph">then we&#8217;ll call on the G function.</p>



<p class="wp-block-paragraph">Then the G function will just throw an exception.</p>



<p class="wp-block-paragraph">We&#8217;ll just pretend that something really bad happened.</p>



<p class="wp-block-paragraph">You crashed or you actually did throw</p>



<p class="wp-block-paragraph">and you didn&#8217;t catch your throw,</p>



<p class="wp-block-paragraph">or maybe the system threw something at you</p>



<p class="wp-block-paragraph">or another library threw something at you</p>



<p class="wp-block-paragraph">and you didn&#8217;t catch it.</p>



<p class="wp-block-paragraph">So just basically a program crash.</p>



<p class="wp-block-paragraph">Let me run this real fast.</p>



<p class="wp-block-paragraph">So make run just to show you that the program crashes.</p>



<p class="wp-block-paragraph">Make run at this point is the same thing as just kind of executing the program.</p>



<p class="wp-block-paragraph">But you can see that it says terminate called after throwing an instance of runtime error.</p>



<p class="wp-block-paragraph">And then there&#8217;s the message, oh my gosh, and then aborted core dumped.</p>



<p class="wp-block-paragraph">That&#8217;s not good.</p>



<p class="wp-block-paragraph">So now let&#8217;s try to understand why.</p>



<p class="wp-block-paragraph">Why did that crash?</p>



<p class="wp-block-paragraph">Pretend you don&#8217;t know that it happened in G. You know, you&#8217;re trying to investigate.</p>



<p class="wp-block-paragraph">So we could type GDB and then we could type a file to load the debug symbols, but it&#8217;s a little bit faster just to type GDB main and just sort of name the file that you want to load right away.</p>



<p class="wp-block-paragraph">So if I do that, notice how it automatically tries to load the debug symbols from main.</p>



<p class="wp-block-paragraph">Then I can just type run and then the program tries to run and notice how it actually catches the crash.</p>



<p class="wp-block-paragraph">If you look down here, terminate called after throwing an instance of runtime error.</p>



<p class="wp-block-paragraph">throwing an instance of runtime error so that&#8217;s what the program thinks is going on but then the</p>



<p class="wp-block-paragraph">program is trying to terminate but then down here gdb is like wait wait wait i just caught you know</p>



<p class="wp-block-paragraph">a termination uh getting invoked here and you can see this is sort of system code like we did not</p>



<p class="wp-block-paragraph">create this source file p thread kill we didn&#8217;t write that that&#8217;s the standard library and there&#8217;s</p>



<p class="wp-block-paragraph">a function here called p thread kill implementation with those you know fun c underscore prefixes</p>



<p class="wp-block-paragraph">prefixes everywhere and so this is like some sort of a c source file and we don&#8217;t have that file on</p>



<p class="wp-block-paragraph">the system so we can&#8217;t really debug that file lucky for you most of these standard libraries</p>



<p class="wp-block-paragraph">work all the time so you don&#8217;t really need to debug them you need to debug your code instead</p>



<p class="wp-block-paragraph">of the standard library code so the question really is how did i get here how did i get to</p>



<p class="wp-block-paragraph">this crash so the next command we&#8217;ll learn in gdb is just the where command the where command will</p>



<p class="wp-block-paragraph">I&#8217;m going to release a video in the future that kind of explains call stacks, but basically</p>



<p class="wp-block-paragraph">imagine a abstract data type, a data structure called a stack. And every time you want to add</p>



<p class="wp-block-paragraph">data to the stack, it just sort of stacks up on top of the last piece of data. So like if I add</p>



<p class="wp-block-paragraph">something, let&#8217;s say I want to add the number five, then I would just add the number five on top of</p>



<p class="wp-block-paragraph">the stack, right? If I wanted to add the number 11, then I would just add the number 11 onto the</p>



<p class="wp-block-paragraph">off of the stack and the stack is a really good data structure to uh sort of give you a trail of</p>



<p class="wp-block-paragraph">breadcrumbs to know where you got where did you come from so we call this the call stack because</p>



<p class="wp-block-paragraph">what&#8217;s happening is every single time you call a function then the new scope and then you know the</p>



<p class="wp-block-paragraph">new function that you&#8217;re invoking um it has something called a call frame full of information</p>



<p class="wp-block-paragraph">current address is and all that stuff.</p>



<p class="wp-block-paragraph">And we&#8217;ll just call that chunk of data that belongs to one instance of a function call.</p>



<p class="wp-block-paragraph">We&#8217;ll just call that a call frame.</p>



<p class="wp-block-paragraph">And so if you&#8217;re stacking call frames one on top of the other,</p>



<p class="wp-block-paragraph">then we call that whole entire thing the call stack.</p>



<p class="wp-block-paragraph">And this is what allows us to use recursion and all these complicated call graphs and everything.</p>



<p class="wp-block-paragraph">It&#8217;s really simple, but it&#8217;s really powerful.</p>



<p class="wp-block-paragraph">So you&#8217;re looking at the call stack.</p>



<p class="wp-block-paragraph">Each one of these lines is the call frame or is a call frame.</p>



<p class="wp-block-paragraph">And so for example, if you just look at number zero here, you&#8217;re looking at call frame zero,</p>



<p class="wp-block-paragraph">which is the closest frame to wherever the crash occurred, which is if you look at it,</p>



<p class="wp-block-paragraph">that&#8217;s exactly what we were looking at when we saw that original message, right? Call frame zero.</p>



<p class="wp-block-paragraph">So that&#8217;s not really useful. You want to go down to higher numbered call frames or I guess</p>



<p class="wp-block-paragraph">physically lowered number call frames and just kind of scan it until you find some code that</p>



<p class="wp-block-paragraph">raise no abort no none of this stuff is ours live standard c plus plus no the first frame that</p>



<p class="wp-block-paragraph">contains code that is ours is call frame number nine or i guess like nine away from our current</p>



<p class="wp-block-paragraph">position so i guess find the physically highest call frame that is your code or the lowest numbered</p>



<p class="wp-block-paragraph">call frame that is your code and it&#8217;s telling us right here all right we uh we actually seem to</p>



<p class="wp-block-paragraph">So if I go to 65, right there, it tells you exactly where the crash happened.</p>



<p class="wp-block-paragraph">If you&#8217;re still trying to figure out, well, how did I get to that crash?</p>



<p class="wp-block-paragraph">I don&#8217;t know how that actually happened.</p>



<p class="wp-block-paragraph">Just keep looking down further in the call frames.</p>



<p class="wp-block-paragraph">The next one, call frame 10, says, well, we were inside of function f with input equals</p>



<p class="wp-block-paragraph">three at main.cpb line 46.</p>



<p class="wp-block-paragraph">So if I just go to 46, I can get another clue.</p>



<p class="wp-block-paragraph">I can go, all right, so for some reason we called g.</p>



<p class="wp-block-paragraph">Imagine again, this program is much more complicated.</p>



<p class="wp-block-paragraph">And then if we&#8217;re still confused, we just look down at another one and it&#8217;s like, well, this all this whole mess started at CPP main dot CPP line 28.</p>



<p class="wp-block-paragraph">So if we look at line 28, it&#8217;s like, well, we were inside of this loop and we we called the F function and then the F function called the G function.</p>



<p class="wp-block-paragraph">And then G just kind of did a throw. So that gives us a lot of information.</p>



<p class="wp-block-paragraph">All right. Next thing we can do is we can sort of move up and down the call stack, because right now we&#8217;re sitting at call frame zero, which is just the system code.</p>



<p class="wp-block-paragraph">which is just the system code, but maybe we don&#8217;t understand why the throw actually happened at,</p>



<p class="wp-block-paragraph">let&#8217;s say, line 65, right? So we can use up to go up in the call stack to a different call frame.</p>



<p class="wp-block-paragraph">So if I hit up, notice how it mentions that we&#8217;re now in frame number one instead of zero.</p>



<p class="wp-block-paragraph">And if I do up again, we&#8217;re now in frame two, which is a little bit closer. We can use the</p>



<p class="wp-block-paragraph">trick finally where we hit the enter key instead of repeating the command. So I&#8217;m just going to</p>



<p class="wp-block-paragraph">and hit enter a couple times until we eventually get to our code,</p>



<p class="wp-block-paragraph">which I think was supposed to be at frame nine.</p>



<p class="wp-block-paragraph">So I&#8217;m just going to hit it a bunch of times until we get to frame nine.</p>



<p class="wp-block-paragraph">Now we&#8217;re looking sort of back in time at that point</p>



<p class="wp-block-paragraph">because all these other frames actually did get invoked,</p>



<p class="wp-block-paragraph">but we don&#8217;t really care about what was going on inside of them</p>



<p class="wp-block-paragraph">because they probably did their job correctly.</p>



<p class="wp-block-paragraph">We&#8217;re looking at our code, so we&#8217;re going back in time</p>



<p class="wp-block-paragraph">right when we were doing this throw.</p>



<p class="wp-block-paragraph">Oh no, we threw. Why did we throw?</p>



<p class="wp-block-paragraph">well there&#8217;s another command in gdb called info locals</p>



<p class="wp-block-paragraph">okay the info locals uh there&#8217;s there&#8217;s really not much to this maybe maybe let me do this again</p>



<p class="wp-block-paragraph">a equals five and uh then i&#8217;ll just say a plus plus just so that we have a local variable</p>



<p class="wp-block-paragraph">i forgot that gdb doesn&#8217;t consider the incoming arguments as locals so there was nothing there</p>



<p class="wp-block-paragraph">real fast uh gdp oh let&#8217;s do make build and then gdp main and then run and then we have a throw</p>



<p class="wp-block-paragraph">and then i say where and then i go up up up up to a frame you can also use the keyword down if you</p>



<p class="wp-block-paragraph">go too far if you want to go you know back down in the call stack but i&#8217;m just going to use up</p>



<p class="wp-block-paragraph">okay so now we have it here now finally i think i can do info locals just to see the local variables</p>



<p class="wp-block-paragraph">notice how the a variable is there now because I just added a local variable a a moment ago</p>



<p class="wp-block-paragraph">you can also print things directly you can say print the input incoming variable if you&#8217;re in</p>



<p class="wp-block-paragraph">assembly you can also print registers you can say info registers like that and you&#8217;ll get a nice</p>



<p class="wp-block-paragraph">print out of all the registers you could print individual registers you can say let&#8217;s print</p>



<p class="wp-block-paragraph">register r12 you can print register r12 as binary by saying I think it&#8217;s p slash t</p>



<p class="wp-block-paragraph">or print slash t yeah we can probably just do print slash t also</p>



<p class="wp-block-paragraph">t stands for two because they&#8217;re it&#8217;s a base two number system</p>



<p class="wp-block-paragraph">does that mean there&#8217;s a p slash h or a p slash f for 15 or 16 s for 16 i don&#8217;t know i haven&#8217;t</p>



<p class="wp-block-paragraph">tried that is it going to work hang on p slash s bar 12 it&#8217;s not going to work nope didn&#8217;t work</p>



<p class="wp-block-paragraph">i think it thinks it&#8217;s a character point or something but anyway so we can print a lot of</p>



<p class="wp-block-paragraph">So we can print a lot of stuff.</p>



<p class="wp-block-paragraph">And like I said before, we can go up and down the call stack.</p>



<p class="wp-block-paragraph">So I can go down a couple times and then go back up again.</p>



<p class="wp-block-paragraph">And now we can assume that we&#8217;ve kind of debugged, you know, where the source of the error was.</p>



<p class="wp-block-paragraph">So I&#8217;m going to comment that call out to G and run the program again one more time with a different error.</p>



<p class="wp-block-paragraph">So I&#8217;ve commented this code out from before, but just imagine now that we&#8217;re going to use some pointers.</p>



<p class="wp-block-paragraph">We&#8217;re going to start off with a pointer called P.</p>



<p class="wp-block-paragraph">a pointer called p we&#8217;re going to set it to null at the beginning and then we&#8217;re going to just</p>



<p class="wp-block-paragraph">kind of allocate it and then we&#8217;re going to set you know a value and then we&#8217;re going to dereference</p>



<p class="wp-block-paragraph">it and dereferencing a pointer just kind of sets the first value in an array you can do that and</p>



<p class="wp-block-paragraph">then we&#8217;re going to deallocate the pointer and then how about right after that we do something</p>



<p class="wp-block-paragraph">really really naughty we say p at some index is equal to a five this should be this should be a</p>



<p class="wp-block-paragraph">a program crash because we deallocated p already at that point we would be dealing with junk data</p>



<p class="wp-block-paragraph">if we tried to dereference p but to make it even more clear that it&#8217;s naughty we&#8217;ll set it to a no</p>



<p class="wp-block-paragraph">pointer and then we&#8217;ll try to actually use it so let me let me just restart the program real fast</p>



<p class="wp-block-paragraph">i&#8217;m gonna do quit yes and then we&#8217;ll do make a debug just so you know my make debug is just a</p>



<p class="wp-block-paragraph">Let&#8217;s see, where&#8217;s that? Where&#8217;s that? Where&#8217;s that? Do I not have a debug shortcut yet?</p>



<p class="wp-block-paragraph">Oh dear. I need to add that before this video is over. You know what? I&#8217;ll add it right now.</p>



<p class="wp-block-paragraph">We&#8217;ll do this run and we&#8217;ll say debug, make debug, and it needs to build first. And then I&#8217;ll say</p>



<p class="wp-block-paragraph">debugging the program. And then we will do the GDB binary and give it an argument of</p>



<p class="wp-block-paragraph">the executable and then later we can we can upgrade this to take a little script of commands</p>



<p class="wp-block-paragraph">because the commands are going to start getting out of control so now if i do make debug if i</p>



<p class="wp-block-paragraph">didn&#8217;t screw it up now it at least goes in there and i&#8217;ll do run and then we have a seg fault and</p>



<p class="wp-block-paragraph">notice how it tells us right away hey you have a seg fault right here you&#8217;re accessing invalid</p>



<p class="wp-block-paragraph">memory let&#8217;s do info locals just to see what&#8217;s up oh the p is actually a zero that&#8217;s a null pointer</p>



<p class="wp-block-paragraph">explicitly oh whoops you know oh what have I done but it&#8217;s a really good idea to set your</p>



<p class="wp-block-paragraph">pointers to null after you deallocate because if you don&#8217;t you might end up with undefined</p>



<p class="wp-block-paragraph">behavior where sometimes the program doesn&#8217;t crash while you&#8217;re overriding junk data or reading junk</p>



<p class="wp-block-paragraph">data but sometimes it does and you&#8217;re not really sure like why does it work sometimes and why does</p>



<p class="wp-block-paragraph">it not work sometimes so let me comment this out and see if it&#8217;ll crash uh let&#8217;s just let&#8217;s just</p>



<p class="wp-block-paragraph">make debug and then i&#8217;ll do run and then if we do info locals oh yeah okay so this is uh</p>



<p class="wp-block-paragraph">it did seg fault so that&#8217;s good uh if we were unlucky then the program wouldn&#8217;t have crashed</p>



<p class="wp-block-paragraph">it would have just started behaving strangely and um when we print out the value of p notice how it</p>



<p class="wp-block-paragraph">looks like a pointer still like if we were to debug the program and print the pointer value</p>



<p class="wp-block-paragraph">then it doesn&#8217;t really it looks the same it looks the same after we deallocated it right so that</p>



<p class="wp-block-paragraph">this is called a dangling pointer meaning you deallocated the pointer but you forgot to set</p>



<p class="wp-block-paragraph">it to null afterwards so then later when you&#8217;re trying to debug the program it&#8217;s a little confusing</p>



<p class="wp-block-paragraph">because you&#8217;re like that looks like a regular pointer what did i do wrong so um it&#8217;s really</p>



<p class="wp-block-paragraph">good practice to set your pointers to null right after you deallocate them that way when you&#8217;re</p>



<p class="wp-block-paragraph">debugging later because something crashed instead of seeing a memory location on p you&#8217;ll see</p>



<p class="wp-block-paragraph">On P, you&#8217;ll see something that looks definitely like a null pointer and print P.</p>



<p class="wp-block-paragraph">Then it&#8217;s way easier to realize, oh, whoops, I was trying to use a dead pointer, a pointer that I deallocated.</p>



<p class="wp-block-paragraph">Hopefully that makes sense so far.</p>



<p class="wp-block-paragraph">Next thing I want to do is a small upgrade.</p>



<p class="wp-block-paragraph">I can&#8217;t remember if it&#8217;s dash X or dash EX.</p>



<p class="wp-block-paragraph">I think it&#8217;s dash X.</p>



<p class="wp-block-paragraph">But you can write a little script.</p>



<p class="wp-block-paragraph">I have a little script here called Good Doggo.</p>



<p class="wp-block-paragraph">called good doggo you can just make any file name it anything you want i&#8217;m so i&#8217;m just naming it</p>



<p class="wp-block-paragraph">good doggo.txt because my dog&#8217;s taking a little nap behind me as usual um but you could name this</p>



<p class="wp-block-paragraph">gdb.txt or whatever it is you want so you can put inside of this script file any command that you</p>



<p class="wp-block-paragraph">want gdb to execute when it launches so let&#8217;s just comment this stuff out real fast and i&#8217;ll do</p>



<p class="wp-block-paragraph">I&#8217;ll just do run maybe for starters.</p>



<p class="wp-block-paragraph">Because whenever I&#8217;ve been launching for debug,</p>



<p class="wp-block-paragraph">I launch with GDB and then I type run manually, right?</p>



<p class="wp-block-paragraph">So I want to save a little time.</p>



<p class="wp-block-paragraph">So good doggo is the name of the script.</p>



<p class="wp-block-paragraph">So when I invoke GDB, I am going to,</p>



<p class="wp-block-paragraph">where is it right there?</p>



<p class="wp-block-paragraph">Okay, it&#8217;s GDB.</p>



<p class="wp-block-paragraph">And then I&#8217;m going to go dot, I think it&#8217;s X.</p>



<p class="wp-block-paragraph">And then I&#8217;m going to say good doggo.txt.</p>



<p class="wp-block-paragraph">If it&#8217;s not dash x, then it&#8217;s dash ex.</p>



<p class="wp-block-paragraph">One of those executes the command that comes after,</p>



<p class="wp-block-paragraph">and one of those executes the command script that comes after.</p>



<p class="wp-block-paragraph">Let me just double check that this actually is going to work.</p>



<p class="wp-block-paragraph">So make debug.</p>



<p class="wp-block-paragraph">All right, okay, so it was dash x.</p>



<p class="wp-block-paragraph">Dash x specifies a script that will be run.</p>



<p class="wp-block-paragraph">Dash ex just specifies a command that you can put right in there.</p>



<p class="wp-block-paragraph">Like I could have said dash ex run, and it would have ran right away.</p>



<p class="wp-block-paragraph">But the script is more convenient, right?</p>



<p class="wp-block-paragraph">Because we can save typing.</p>



<p class="wp-block-paragraph">So notice how it ran right away and then there&#8217;s a seg fault.</p>



<p class="wp-block-paragraph">Okay, so now let&#8217;s go a little bit deeper.</p>



<p class="wp-block-paragraph">Let&#8217;s change this to false again now that we understand like null pointers and all that</p>



<p class="wp-block-paragraph">stuff.</p>



<p class="wp-block-paragraph">So we can just basically deal a little bit more with only what the main loop is doing.</p>



<p class="wp-block-paragraph">Suppose we just still don&#8217;t really understand what the loop is doing, why our answer is</p>



<p class="wp-block-paragraph">you know, good or bad.</p>



<p class="wp-block-paragraph">So maybe I want to do a breakpoint at the top of that for loop.</p>



<p class="wp-block-paragraph">loop gets to the top of its iteration, I want the program to pause so I can look around.</p>



<p class="wp-block-paragraph">So I&#8217;m going to set up a breakpoint on line 22. And here&#8217;s how you set up breakpoints</p>



<p class="wp-block-paragraph">in GDB. I&#8217;m going to go ahead and maybe do the terminal for now. And then I&#8217;ll stick that into</p>



<p class="wp-block-paragraph">the script next. I will not remember that it&#8217;s line 22. That&#8217;s okay. I&#8217;m going to do quit.</p>



<p class="wp-block-paragraph">And I&#8217;m going to do make build. Then I&#8217;m going to go GDB main just to jump in there.</p>



<p class="wp-block-paragraph">and then i&#8217;m going to say break or just the letter b just to make a break point you type the name of</p>



<p class="wp-block-paragraph">the source code file that you want to break in and then a colon and then the line number where</p>



<p class="wp-block-paragraph">you want it to break so i think i think it actually was line 22 oh i can see it and then</p>



<p class="wp-block-paragraph">maybe i want to have it break at line i don&#8217;t know maybe right here line 25 right before it increases</p>



<p class="wp-block-paragraph">And then so I&#8217;m going to do an up arrow to just repeat the command so I can edit it real fast.</p>



<p class="wp-block-paragraph">And then I&#8217;ll break again at line 28 and then maybe 30 and then 32.</p>



<p class="wp-block-paragraph">So I&#8217;m going to go 28, 30 and 32.</p>



<p class="wp-block-paragraph">30 and I&#8217;m just making up break points.</p>



<p class="wp-block-paragraph">I just want to inspect the program and then maybe I&#8217;ll break at line 36 so I can see what the final answer is.</p>



<p class="wp-block-paragraph">So I just have a bunch of break points set up.</p>



<p class="wp-block-paragraph">Remember when the program is running now under GDB, every time it hits one of those lines,</p>



<p class="wp-block-paragraph">every time it hits one of those lines the program will pause and i&#8217;ll have a chance to look around</p>



<p class="wp-block-paragraph">at the variables and things so i&#8217;m not sure if i&#8217;ve set up the breakpoints correctly i can say</p>



<p class="wp-block-paragraph">info breakpoints and it&#8217;ll show me all of my breakpoints notice how you can enable them and</p>



<p class="wp-block-paragraph">disable them so let&#8217;s say for the sake of argument i want to disable the breakpoint at line 30 because</p>



<p class="wp-block-paragraph">maybe i don&#8217;t really need that right now but i kind of want to keep it in the system for later</p>



<p class="wp-block-paragraph">disable four because it&#8217;s number four.</p>



<p class="wp-block-paragraph">It&#8217;s breakpoint number four.</p>



<p class="wp-block-paragraph">So I can say disable four.</p>



<p class="wp-block-paragraph">Then if I do info breakpoints again,</p>



<p class="wp-block-paragraph">notice how there&#8217;s a little N on there,</p>



<p class="wp-block-paragraph">meaning breakpoint four is disabled.</p>



<p class="wp-block-paragraph">So I could re-enable it with a four</p>



<p class="wp-block-paragraph">and then go info breakpoints again.</p>



<p class="wp-block-paragraph">So now they&#8217;re all enabled.</p>



<p class="wp-block-paragraph">I am going to maybe copy this into the script file real fast</p>



<p class="wp-block-paragraph">so I don&#8217;t have to keep typing this over and over and over again.</p>



<p class="wp-block-paragraph">Imagine if every single time you changed your program and recompiled it you had to type all of the breakpoints from scratch</p>



<p class="wp-block-paragraph">That&#8217;s why I want you to use this little breakpoint script</p>



<p class="wp-block-paragraph">So we&#8217;re going to do B to break at main.cpp line 22 and 25 and</p>



<p class="wp-block-paragraph">28 and</p>



<p class="wp-block-paragraph">30 and 32. I should have copy pasted the three dang it 36</p>



<p class="wp-block-paragraph">And after we&#8217;re done setting up all the breakpoints</p>



<p class="wp-block-paragraph">show me the breakpoints just so I can have a visual reminder. Keep in mind if you change too</p>



<p class="wp-block-paragraph">much of your source code then you&#8217;re probably going to have to update these lines and that&#8217;s</p>



<p class="wp-block-paragraph">okay but it&#8217;s a good idea to just at least you know kind of look at them a little bit so that&#8217;s</p>



<p class="wp-block-paragraph">why I&#8217;m saying info breakpoints. And so then remember again the makefile all it&#8217;s doing when</p>



<p class="wp-block-paragraph">I type make debug is it&#8217;s just launching this command right here it&#8217;s just saying gdb with the</p>



<p class="wp-block-paragraph">with my gdb script so let me quit to get out of this and then i&#8217;m going to say clear and make</p>



<p class="wp-block-paragraph">debug and notice how it did all that stuff for me it added the breakpoints it showed me the break</p>



<p class="wp-block-paragraph">points and then it ran the program like i told it to and then it already broke on a breakpoint it</p>



<p class="wp-block-paragraph">already break it break breakened it&#8217;s broken i don&#8217;t know i don&#8217;t think it&#8217;s broken uh so we&#8217;re</p>



<p class="wp-block-paragraph">So we&#8217;re on breakpoint number one on line 22.</p>



<p class="wp-block-paragraph">And here&#8217;s the for loop.</p>



<p class="wp-block-paragraph">I can type all of my inspection stuff.</p>



<p class="wp-block-paragraph">I can say info locals.</p>



<p class="wp-block-paragraph">I can say print I, I can say print A, I can print whatever I want.</p>



<p class="wp-block-paragraph">And then when I&#8217;m done kind of looking around and inspecting things,</p>



<p class="wp-block-paragraph">I want to continue the program.</p>



<p class="wp-block-paragraph">I don&#8217;t want to just stop it here.</p>



<p class="wp-block-paragraph">So I&#8217;m just going to use the command continue.</p>



<p class="wp-block-paragraph">And it goes right to the next breakpoint.</p>



<p class="wp-block-paragraph">If I want to, you know, continue again, I can hit C.</p>



<p class="wp-block-paragraph">continue again i can hit c or i can just hit enter you know to just sort of keep continuing as i</p>



<p class="wp-block-paragraph">inspect and print things let&#8217;s see when can i get to break point number one is that what&#8217;s going on</p>



<p class="wp-block-paragraph">here hang on a second what is break point number one oh i know what to do info break points</p>



<p class="wp-block-paragraph">break point number one is that main.cpp line 22 is that actually going to get hit oh it&#8217;s</p>



<p class="wp-block-paragraph">having issues here with my GUI. Okay. Line 22. Okay. So it&#8217;s not really hitting that anymore.</p>



<p class="wp-block-paragraph">I guess it&#8217;s not going to think that it hits the top of the forelip. Okay. So I guess breakpoint</p>



<p class="wp-block-paragraph">two is where we&#8217;re always going to be hitting. So let&#8217;s just suppose that I&#8217;m continuing until</p>



<p class="wp-block-paragraph">I hit breakpoint number two. Suppose that the next 10 times I see breakpoint two, I don&#8217;t</p>



<p class="wp-block-paragraph">actually want to stop and break on it. I just want to skip the next 10 iterations for some reason.</p>



<p class="wp-block-paragraph">some reason you can say continue 10 and it&#8217;ll skip the next 10 times that it hits the number two</p>



<p class="wp-block-paragraph">notice how if i hit continue a bunch of times we&#8217;re not really seeing the break point number</p>



<p class="wp-block-paragraph">two anymore we&#8217;re seeing other break points and then eventually if i hit it enough times</p>



<p class="wp-block-paragraph">we&#8217;ll probably see two again oh my god oh my god are we seeing it yet no</p>



<p class="wp-block-paragraph">Okay, wait, are we seeing I&#8217;m freaking myself out.</p>



<p class="wp-block-paragraph">Okay, so let&#8217;s continue 10 times on breakpoint three, then we&#8217;ll only see</p>



<p class="wp-block-paragraph">breakpoint four, I guess.</p>



<p class="wp-block-paragraph">So we can do continue 10 times on breakpoint four.</p>



<p class="wp-block-paragraph">What is going on here?</p>



<p class="wp-block-paragraph">Did I write this program in a weird way?</p>



<p class="wp-block-paragraph">Hmm.</p>



<p class="wp-block-paragraph">Well, trust me on this.</p>



<p class="wp-block-paragraph">Let&#8217;s continue 100 on breakpoint three and then continue 100 on breakpoint four.</p>



<p class="wp-block-paragraph">breakpoint 4. Okay, so now we&#8217;re just done with the whole entire program. I guess there must have</p>



<p class="wp-block-paragraph">been a 2 there that I missed. So now we&#8217;re finally on breakpoint 6, which is when everything is</p>



<p class="wp-block-paragraph">finished. Let me show you real fast that we can add more breakpoints in assembly just to prove</p>



<p class="wp-block-paragraph">that we can debug assembly real fast. So if I want to debug assembly, I just have to type the name of</p>



<p class="wp-block-paragraph">that source code file. If it was nested in a folder, like if you had like a complicated hierarchy of</p>



<p class="wp-block-paragraph">of source code files you would just need to type the relative path but for now I&#8217;m just going to</p>



<p class="wp-block-paragraph">be able to type the name of the file so assy.asm and let&#8217;s suppose that I want to break at line</p>



<p class="wp-block-paragraph">16 just so I can see the registers that I set up so I&#8217;m going to do 16 and then I&#8217;m going to break</p>



<p class="wp-block-paragraph">at assy.asm line 16 and then I&#8217;m going to run and that actually never gets called does it no no it</p>



<p class="wp-block-paragraph">called does it no no it gets called I think I have a call up here somewhere</p>



<p class="wp-block-paragraph">nope I don&#8217;t have a call okay let&#8217;s make a call this is gonna throw off all of my</p>



<p class="wp-block-paragraph">C++ breakpoints so I&#8217;ll just comment them all out right now comment them all</p>



<p class="wp-block-paragraph">out so I don&#8217;t have to redo them and this is a hybrid program so I&#8217;m gonna go</p>



<p class="wp-block-paragraph">extern what is it extern C make a block where I name the function the reason we</p>



<p class="wp-block-paragraph">name mangling so the AC symbol is going to show up as just its regular function</p>



<p class="wp-block-paragraph">name rather than a bunch of extra stuff indicating the prototype so that we can</p>



<p class="wp-block-paragraph">do overloading so we&#8217;re just going to disable that and then at the very top of</p>



<p class="wp-block-paragraph">the program I&#8217;m just going to call it this should hopefully work let me just</p>



<p class="wp-block-paragraph">do a regular make run just to make sure the whole program compiles okay now</p>



<p class="wp-block-paragraph">debug script we&#8217;re gonna break on line 16 which is going to be letting us see</p>



<p class="wp-block-paragraph">the registers okay so I&#8217;m gonna go make debug notice how it hit the breakpoint</p>



<p class="wp-block-paragraph">in the assembly just the same as the C++ and we can print whatever we want now so</p>



<p class="wp-block-paragraph">I&#8217;m just gonna say info registers and if we look carefully we can kind of see</p>



<p class="wp-block-paragraph">that we modified racks REX is 15 so that&#8217;s expected RDI is 20 which is</p>



<p class="wp-block-paragraph">R12 should be a giant number. Where&#8217;s R12? Right there. So you can see the state of your program at any point in time just by breaking on it.</p>



<p class="wp-block-paragraph">I&#8217;m breaking on a certain line. So this is tremendously useful for debugging not just for higher level languages but also assembly.</p>



<p class="wp-block-paragraph">What else can I do? Oh let&#8217;s put a global in the data section. So I&#8217;m gonna do, I don&#8217;t know, my thing or something like that and we&#8217;ll call it a byte array and I&#8217;ll just go hello.</p>



<p class="wp-block-paragraph">I&#8217;ll say we have a thing one and a thing two.</p>



<p class="wp-block-paragraph">Something like that.</p>



<p class="wp-block-paragraph">And maybe thing two is a null terminated string,</p>



<p class="wp-block-paragraph">whereas thing one is a regular thing.</p>



<p class="wp-block-paragraph">We should be able to print those symbols.</p>



<p class="wp-block-paragraph">If that&#8217;s not true, I&#8217;ll come back at a later time</p>



<p class="wp-block-paragraph">and show you how to do it.</p>



<p class="wp-block-paragraph">Anyway, so we&#8217;ll do make debug</p>



<p class="wp-block-paragraph">to just kind of assemble everything again.</p>



<p class="wp-block-paragraph">And we know how to do info registers.</p>



<p class="wp-block-paragraph">We can print, you know, one register in particular,</p>



<p class="wp-block-paragraph">print R12 if we wanted to.</p>



<p class="wp-block-paragraph">History has not reached.</p>



<p class="wp-block-paragraph">History has not reached 12.</p>



<p class="wp-block-paragraph">Oh, I got to put R12.</p>



<p class="wp-block-paragraph">Yeah, then we can get the, wait a minute, wait a minute.</p>



<p class="wp-block-paragraph">Oh, I threw off the line numbers because I added the variables up here.</p>



<p class="wp-block-paragraph">So now we&#8217;re going to break at 21.</p>



<p class="wp-block-paragraph">Let me just fix that.</p>



<p class="wp-block-paragraph">21.</p>



<p class="wp-block-paragraph">We&#8217;ll do a quit.</p>



<p class="wp-block-paragraph">Make debug again.</p>



<p class="wp-block-paragraph">And now we&#8217;re at 21.</p>



<p class="wp-block-paragraph">If I say info registers, we can see R12 is that big value.</p>



<p class="wp-block-paragraph">you, but we can also print R12 directly. And we should be able to print my thing one, hopefully,</p>



<p class="wp-block-paragraph">has an unknown type, oh, we have to cast it. So we can do like basic casting in GDB. So I&#8217;m going</p>



<p class="wp-block-paragraph">to say this is a character pointer. Remember, all of the assembly symbols are basically pointers,</p>



<p class="wp-block-paragraph">unless it&#8217;s an EQU, EQU variable. In that case, it&#8217;s more of a define. So I&#8217;m going to print</p>



<p class="wp-block-paragraph">and then it says error cannot access the memory add address</p>



<p class="wp-block-paragraph">what the heck did i do wrong how about that cannot access that all right i&#8217;ll come back in</p>



<p class="wp-block-paragraph">another video because this wasn&#8217;t something that i prepared for just to print strings in globals</p>



<p class="wp-block-paragraph">i&#8217;ll come back at some later date in the future like five years from now and i&#8217;ll just show you</p>



<p class="wp-block-paragraph">how to print globals but i hope if you&#8217;re in assembly you probably don&#8217;t need to worry about</p>



<p class="wp-block-paragraph">You just have globals, but the real problem for you is going to be what&#8217;s inside of your registers and so forth.</p>



<p class="wp-block-paragraph">You can also deref, I think.</p>



<p class="wp-block-paragraph">Let me see.</p>



<p class="wp-block-paragraph">Okay, I&#8217;m going to move on from that.</p>



<p class="wp-block-paragraph">So anyway, we got a script and we got a lot of basic GDB commands.</p>



<p class="wp-block-paragraph">Is there anything else that I wanted to show you?</p>



<p class="wp-block-paragraph">Let me just look at my notes real fast here to make sure I&#8217;m not forgetting to say anything.</p>



<p class="wp-block-paragraph">make sure I&#8217;m not forgetting to say anything.</p>



<p class="wp-block-paragraph">So we&#8217;re going to do debug symbols, console, quit, attach to binary,</p>



<p class="wp-block-paragraph">launching the program, uncaught exception, breakpoints, info, delete,</p>



<p class="wp-block-paragraph">enable, disable, run, continue, end times, info registers, printing.</p>



<p class="wp-block-paragraph">Oh, we can print a register in binary.</p>



<p class="wp-block-paragraph">Forgot to show that.</p>



<p class="wp-block-paragraph">So we are at a breakpoint, I think.</p>



<p class="wp-block-paragraph">And if we printed R12 with the regular print, we can also do P slash T to just</p>



<p class="wp-block-paragraph">p slash t to just sort of print it in binary if you want to i think i might have said that already</p>



<p class="wp-block-paragraph">either that or i said that like a couple days ago to some and then we can do info locals and</p>



<p class="wp-block-paragraph">then print a variable and then we get the script file and then we can quit okay so i think this is</p>



<p class="wp-block-paragraph">pretty much everything that i wanted to show you you now have a basic idea of what we can do inside</p>



<p class="wp-block-paragraph">of gdb but keep in mind there is so much more you can do in gdb than i can fit in one video</p>



<p class="wp-block-paragraph">can type help and you can see a list of other major you know areas that gdb can handle um you</p>



<p class="wp-block-paragraph">can do uh let&#8217;s see i think it&#8217;s help and then like we&#8217;ve got information on aliases breakpoints</p>



<p class="wp-block-paragraph">data you know whatever we can do i think help breakpoints to see more information on breakpoint</p>



<p class="wp-block-paragraph">commands yeah so all of the things you can do with breakpoints is like all of these commands here</p>



<p class="wp-block-paragraph">one page we have to enter to see one more page or see to see all of the results without using</p>



<p class="wp-block-paragraph">paging anymore so i&#8217;m just hit c and so there&#8217;s like you know we can save trace points we can</p>



<p class="wp-block-paragraph">try to catch exceptions we can enable disable break points there&#8217;s like unwinders which i&#8217;ve</p>



<p class="wp-block-paragraph">never even used we can bookmark things we can you know start tracing memory we can rethrow</p>



<p class="wp-block-paragraph">variables so just keep in mind gdp is incredibly powerful this video barely scratches the surface</p>



<p class="wp-block-paragraph">but for a programmer who is new to debugging i think this will be very useful to you i hope it is</p>



<p class="wp-block-paragraph">anyway thanks for watching this video i hope you learned a little bit of stuff and had a</p>



<p class="wp-block-paragraph">little bit of fun um i will see you in the next video rest yourself and take a nap and have fun</p>



<p class="wp-block-paragraph">and hug your your loved ones okay I&#8217;m out see you later hey everybody thanks</p>



<p class="wp-block-paragraph">for watching this video again from the bottom of my heart I really appreciate</p>



<p class="wp-block-paragraph">it I do hope you did learn something and have some fun if you could do me a</p>



<p class="wp-block-paragraph">please a small little favor could you please subscribe and follow this channel</p>



<p class="wp-block-paragraph">channel or these videos or whatever it is you do on the current social media</p>



<p class="wp-block-paragraph">website that you&#8217;re looking at right now it would really mean the world to me</p>



<p class="wp-block-paragraph">and it&#8217;ll help make more videos and grow this community so we&#8217;ll be able to do</p>



<p class="wp-block-paragraph">more videos longer videos better videos or just I&#8217;ll be able to keep making</p>



<p class="wp-block-paragraph">videos in general so please do do me a kindness and and subscribe you know</p>



<p class="wp-block-paragraph">sometimes I&#8217;m sleeping in the middle of the night and I just wake up because I</p>



<p class="wp-block-paragraph">know somebody subscribed or followed it just wakes me up and I get filled with</p>



<p class="wp-block-paragraph">That&#8217;s exactly what happens every single time.</p>



<p class="wp-block-paragraph">So you could do it as a nice favor to me,</p>



<p class="wp-block-paragraph">or you could troll me if you want to just wake me up in the middle of the night.</p>



<p class="wp-block-paragraph">Just subscribe, and then I&#8217;ll just wake up.</p>



<p class="wp-block-paragraph">I promise that&#8217;s what will happen.</p>



<p class="wp-block-paragraph">Also, if you look at the middle of the screen right now,</p>



<p class="wp-block-paragraph">you should see a QR code, which you can scan in order to go to the website,</p>



<p class="wp-block-paragraph">which I think is also named somewhere at the bottom of this video.</p>



<p class="wp-block-paragraph">And it&#8217;ll take you to my main website,</p>



<p class="wp-block-paragraph">where you can just kind of like see all the videos I published,</p>



<p class="wp-block-paragraph">and the services and tutorials and things that I offer,</p>



<p class="wp-block-paragraph">and all that good stuff.</p>



<p class="wp-block-paragraph">things that I offer and all that good stuff. And, uh, if you have a suggestion for, uh, uh,</p>



<p class="wp-block-paragraph">clarifications or errata, or just future videos that you want to see, please leave a comment.</p>



<p class="wp-block-paragraph">Or if you just want to say, Hey, what&#8217;s up, what&#8217;s going on? You know, just send me a comment,</p>



<p class="wp-block-paragraph">whatever. I also wake up for those in the middle of the night. I get, I wake up in a cold sweat</p>



<p class="wp-block-paragraph">and I&#8217;m like, it would really, it really mean the world to me. I would really appreciate it. So</p>



<p class="wp-block-paragraph">watching this video and enjoy the cool music as I fade into the darkness which is coming for us all.</p>



<p class="wp-block-paragraph">Thank you.</p>
<p>The post <a href="https://www.NeuralLantern.com/master-gnu-debugger-debug-c-assembly-programs-with-gdb-like-a-pro/">Master GNU Debugger: Debug C++ &amp; Assembly Programs with GDB Like a Pro</a> appeared first on <a href="https://www.NeuralLantern.com">NeuralLantern.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.NeuralLantern.com/master-gnu-debugger-debug-c-assembly-programs-with-gdb-like-a-pro/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How Linkers Work: Linking Code, Virtual Memory, and Module Jumps Explained</title>
		<link>https://www.NeuralLantern.com/how-linkers-work-linking-code-virtual-memory-and-module-jumps-explained/</link>
					<comments>https://www.NeuralLantern.com/how-linkers-work-linking-code-virtual-memory-and-module-jumps-explained/#respond</comments>
		
		<dc:creator><![CDATA[mike]]></dc:creator>
		<pubDate>Mon, 02 Jun 2025 13:04:50 +0000</pubDate>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Videos]]></category>
		<category><![CDATA[assembly programming]]></category>
		<category><![CDATA[C++ programming]]></category>
		<category><![CDATA[code linking]]></category>
		<category><![CDATA[coding tutorials]]></category>
		<category><![CDATA[compilation]]></category>
		<category><![CDATA[computer science]]></category>
		<category><![CDATA[executable files]]></category>
		<category><![CDATA[jump instructions]]></category>
		<category><![CDATA[linker]]></category>
		<category><![CDATA[module linking]]></category>
		<category><![CDATA[object files]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[programming basics]]></category>
		<category><![CDATA[software development]]></category>
		<category><![CDATA[virtual memory]]></category>
		<guid isPermaLink="false">https://www.NeuralLantern.com/?p=139</guid>

					<description><![CDATA[<p>Learn how linkers connect code modules, manage virtual memory, and handle jumps in this beginner-friendly guide to programming! #Linker #Coding</p>
<p>The post <a href="https://www.NeuralLantern.com/how-linkers-work-linking-code-virtual-memory-and-module-jumps-explained/">How Linkers Work: Linking Code, Virtual Memory, and Module Jumps Explained</a> appeared first on <a href="https://www.NeuralLantern.com">NeuralLantern.com</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<figure class="wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
<iframe loading="lazy" title="How Linkers Work: Linking Code, Virtual Memory, and Module Jumps Explained" width="1380" height="776" src="https://www.youtube.com/embed/Q6B9FWCeaFs?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
</div></figure>



<p class="wp-block-paragraph">Hey everyone, let’s talk linkers! In this video, we unpack the general idea of linking in programming—taking your source code, turning it into object files, and stitching them into an executable. We dive into virtual memory, how programs use offsets, and why jump instructions matter across modules. Using simple assembly and C++ examples, we’ll show how linkers lay out modules, handle labels, and make function calls work. Whether you’re a beginner or a coder curious about what happens under the hood, this is for you! Hit subscribe, scan the QR code for more tutorials, and drop a comment with your thoughts or video ideas. Let’s keep learning and have some fun with code! #Programming #Linker #VirtualMemory #CodingExplained</p>



<p class="wp-block-paragraph">Introduction to Linking 00:00:00<br>Compilation and Object Files 00:00:05<br>Linker Overview 00:00:32<br>Virtual Memory Explanation 00:00:42<br>Program Memory Offsets 00:01:18<br>Jump Instructions in Modules 00:02:54<br>Module Address Space 00:03:38<br>Assembler and Label Jumps 00:04:02<br>Linker’s Role in Module Layout 00:07:15<br>Function Calls Across Modules 00:08:04<br>Marking Labels as Global 00:09:31<br>External Function Calls 00:10:23<br>Data in Executables 00:11:12<br>Conclusion and Call to Subscribe 00:12:08</p>



<p class="wp-block-paragraph">Thanks for watching!</p>



<p class="wp-block-paragraph">Find us on other social media here:</p>



<ul class="wp-block-list">
<li>https://www.NeuralLantern.com/social</li>
</ul>



<p class="wp-block-paragraph">Please help support us!</p>



<ul class="wp-block-list">
<li>Subscribing + Sharing on Social Media</li>



<li>Leaving a comment or suggestion</li>



<li>Subscribing to our Blog</li>



<li>Watching the main &#8220;pinned&#8221; video of this channel for offers and extras</li>
</ul>



<p class="wp-block-paragraph">Hey there, I want to talk to you very quickly about the general idea of linking your programs.</p>



<p class="wp-block-paragraph">In previous videos I&#8217;ve described exactly how to perform the linking stage when you&#8217;re compiling</p>



<p class="wp-block-paragraph">a program. So you write some source code, you compile the source code into object files,</p>



<p class="wp-block-paragraph">you know each file becomes one individual object file, and then when we&#8217;re done we take all the</p>



<p class="wp-block-paragraph">object files and we link them up into an executable program. So I&#8217;ve talked about that</p>



<p class="wp-block-paragraph">I just wanted to talk to you about the general idea of the linking stage in general.</p>



<p class="wp-block-paragraph">Like what is the linker? What is its job? What is it actually doing?</p>



<p class="wp-block-paragraph">So try to keep in mind for starters, each program uses virtual memory.</p>



<p class="wp-block-paragraph">It uses a virtual memory space.</p>



<p class="wp-block-paragraph">So obviously on your computer you have real memory,</p>



<p class="wp-block-paragraph">but there&#8217;s lots of layers of abstraction between the physical hardware</p>



<p class="wp-block-paragraph">the physical hardware and the program that&#8217;s running for starters the operating system uses</p>



<p class="wp-block-paragraph">a paging system the memory stick the memory circuitry might be doing something else for</p>



<p class="wp-block-paragraph">error checking or just you know transport or whatever so so try and bear in mind that each</p>



<p class="wp-block-paragraph">program thinks that it&#8217;s it thinks that itself is kind of the beginning of memory you could imagine</p>



<p class="wp-block-paragraph">it as each program thinks that its first memory location that it has assigned to it is memory</p>



<p class="wp-block-paragraph">location zero but that wouldn&#8217;t necessarily be the case on the computer</p>



<p class="wp-block-paragraph">your operating system probably would have come up with an offset let&#8217;s say</p>



<p class="wp-block-paragraph">for example you know your computer decides to launch your program it</p>



<p class="wp-block-paragraph">creates a process it finds a chunk of memory that&#8217;s available across you know</p>



<p class="wp-block-paragraph">one or more pages of free memory and let&#8217;s say for the sake of argument that</p>



<p class="wp-block-paragraph">the starting offset for the for the quote-unquote real forgetting the other</p>



<p class="wp-block-paragraph">layers layers of abstraction the real memory location of your program is going</p>



<p class="wp-block-paragraph">of your program is going to be let&#8217;s just say like a thousand I know that&#8217;s</p>



<p class="wp-block-paragraph">real unrealistically too low but let&#8217;s just say a thousand and then let&#8217;s say</p>



<p class="wp-block-paragraph">that your program then thinks that it starts at memory location zero that</p>



<p class="wp-block-paragraph">means if your program wants to access memory location 100 then under the hood</p>



<p class="wp-block-paragraph">at the last moment right before you actually hit the RAM stick or hit the</p>



<p class="wp-block-paragraph">page file system a translation has to be performed so if your program is trying</p>



<p class="wp-block-paragraph">what actually happens is you know the general offset for the entire program</p>



<p class="wp-block-paragraph">gets added to memory location 100 and then that tells the computer or the</p>



<p class="wp-block-paragraph">operating system that what you&#8217;re actually trying to do in your program is</p>



<p class="wp-block-paragraph">access memory location 1100 so keep in mind all of this memory is virtual</p>



<p class="wp-block-paragraph">and the modules themselves also need to know where to jump when I say where to</p>



<p class="wp-block-paragraph">Well, suppose for the sake of argument, you have a program that has some jump instructions</p>



<p class="wp-block-paragraph">or go to instructions or like some conditional branching instructions, anything where execution</p>



<p class="wp-block-paragraph">is not just going to go to the very next statement.</p>



<p class="wp-block-paragraph">Execution is going to go somewhere else.</p>



<p class="wp-block-paragraph">Like maybe you have an if else block.</p>



<p class="wp-block-paragraph">It&#8217;s got to maybe jump sometimes down to the else part instead of the top if part.</p>



<p class="wp-block-paragraph">And then when it&#8217;s done executing, it&#8217;s going to jump until after the whole block, you know,</p>



<p class="wp-block-paragraph">There will be lots of times in all of your programs where execution kind of has to jump</p>



<p class="wp-block-paragraph">around somewhere if the program is even a little bit complicated.</p>



<p class="wp-block-paragraph">So that could be a jump instruction, go to in a higher level language, not assembly necessarily,</p>



<p class="wp-block-paragraph">jump if not equal and so forth.</p>



<p class="wp-block-paragraph">So if you imagine writing one module, you could also imagine that the module has its</p>



<p class="wp-block-paragraph">own virtual memory address space.</p>



<p class="wp-block-paragraph">Just imagine it for now.</p>



<p class="wp-block-paragraph">And maybe it starts at zero.</p>



<p class="wp-block-paragraph">at zero that&#8217;s that&#8217;s not what we&#8217;re going to say but just like imagine the module only really knows</p>



<p class="wp-block-paragraph">about itself and so sometimes when you&#8217;re jumping for example if we&#8217;re going to jump uh when</p>



<p class="wp-block-paragraph">something is not equal to something else we&#8217;ll jump to some label and in order to jump to that</p>



<p class="wp-block-paragraph">label the assembler needs to know you know where is that label inside of your source code so pretend</p>



<p class="wp-block-paragraph">just for a moment this is not like a real assembly program but just pretend for a moment that we have</p>



<p class="wp-block-paragraph">and maybe this is like I don&#8217;t know the main label that gets jumped into from GCC and</p>



<p class="wp-block-paragraph">so then we have like a label down here outside and we&#8217;ll do stuff and then jump back to the</p>



<p class="wp-block-paragraph">original point so we probably have to do a label here main finish this is this is bad form but I&#8217;m</p>



<p class="wp-block-paragraph">So if we jump, let&#8217;s compare, I don&#8217;t know, one with two or something.</p>



<p class="wp-block-paragraph">Let&#8217;s compare RAX to RDX and we&#8217;ll just move RAX the value one and move RDX the value two</p>



<p class="wp-block-paragraph">so they&#8217;re not actually equal.</p>



<p class="wp-block-paragraph">And then we compare them and then we say, all right, jump if they&#8217;re not equal to this label.</p>



<p class="wp-block-paragraph">So definitely now we know, oh, we are going to jump down to that label.</p>



<p class="wp-block-paragraph">So execution is going to go directly down to here.</p>



<p class="wp-block-paragraph">we&#8217;ll do something and then eventually maybe we want to jump back so we&#8217;ll say uh</p>



<p class="wp-block-paragraph">maybe let&#8217;s do it again let&#8217;s do let&#8217;s do like a whole set of statements again we&#8217;ll say jump</p>



<p class="wp-block-paragraph">if it is equal and we&#8217;ll just like load those two registers so one and one and then compare</p>



<p class="wp-block-paragraph">them and then say jump if it is equal to main finish this is not a video about conditional</p>



<p class="wp-block-paragraph">branching or jumping i&#8217;m trying to make this as simple as i can but i hope you understand the</p>



<p class="wp-block-paragraph">but i hope you understand the point is just basically we&#8217;re jumping around within the same</p>



<p class="wp-block-paragraph">module right so it&#8217;s easy for the program to understand where to jump if it&#8217;s in the same</p>



<p class="wp-block-paragraph">module or i guess the the object file when we&#8217;re assembling it it&#8217;s easy to understand where to jump</p>



<p class="wp-block-paragraph">because if we&#8217;re at line 8 here when we start to jump and then the actual label here has its first</p>



<p class="wp-block-paragraph">instruction at line 17 well then it you know the amount of instructions to move is just the</p>



<p class="wp-block-paragraph">the difference you know so it&#8217;s easy to say all right if our virtual address is you know this</p>



<p class="wp-block-paragraph">when we jump and we&#8217;re going to jump this much of a difference based on where the label is then now</p>



<p class="wp-block-paragraph">we can just compute the new virtual address to jump or the absolute address or whatever you want</p>



<p class="wp-block-paragraph">to whatever you want to do on that particular run but how does it know where to jump in another</p>



<p class="wp-block-paragraph">module because when we assemble this module as an object file the assembler is only running one pass</p>



<p class="wp-block-paragraph">one pass on just this object file it doesn&#8217;t really know the addresses in the other modules</p>



<p class="wp-block-paragraph">it doesn&#8217;t know their offsets of its labels even if it&#8217;s a c plus plus or a c module it doesn&#8217;t</p>



<p class="wp-block-paragraph">really know the offsets it doesn&#8217;t know where the functions start and end doesn&#8217;t know anything</p>



<p class="wp-block-paragraph">because right now if we assemble this one source code it&#8217;s only going to know about this one source</p>



<p class="wp-block-paragraph">code right and the same goes for the other modules if we compile a c plus plus program to an object</p>



<p class="wp-block-paragraph">a function or you know do a go to statement or something into one of these labels from this</p>



<p class="wp-block-paragraph">module the c plus plus program won&#8217;t really know where it is it won&#8217;t know what address it&#8217;s at it</p>



<p class="wp-block-paragraph">won&#8217;t know the offset right so that&#8217;s the job of the linker the linker looks at all of these labels</p>



<p class="wp-block-paragraph">and all of these uh conditional branching statements and jump statements and everything</p>



<p class="wp-block-paragraph">and it just decides for starters it decides where each module is going to start in memory so maybe</p>



<p class="wp-block-paragraph">I don&#8217;t know if your C++ module starts up here somewhere and then it&#8217;ll say this assembly module</p>



<p class="wp-block-paragraph">starts right after it and then another module right after that and it&#8217;ll just kind of decide</p>



<p class="wp-block-paragraph">where every module will start in the final executable that we&#8217;re actually linking together.</p>



<p class="wp-block-paragraph">Once it decides the layout then it knows the offset of all the different modules and therefore</p>



<p class="wp-block-paragraph">it can compute the additional offset that it would take to get to all the labels. So then at that</p>



<p class="wp-block-paragraph">Your C++ module will make a function call inside of, you know, some assembly module like the one we&#8217;re looking at, assuming it was written a little bit differently.</p>



<p class="wp-block-paragraph">Main finish return.</p>



<p class="wp-block-paragraph">I guess the way it&#8217;s written down here, it&#8217;s returning to main if we just kind of execute it as we&#8217;re looking at it.</p>



<p class="wp-block-paragraph">But another module could could call main finish as a function and still get a return statement.</p>



<p class="wp-block-paragraph">That would actually work, even though it&#8217;s probably bad design.</p>



<p class="wp-block-paragraph">that your assembly sorry your C++ program wants to call a function called</p>



<p class="wp-block-paragraph">main finish inside of this module the linker having already laid out the</p>



<p class="wp-block-paragraph">modules and and being aware of all their offsets it knows okay so you know this</p>



<p class="wp-block-paragraph">assembly module it was underneath the C++ module so it&#8217;ll just take that offset</p>



<p class="wp-block-paragraph">and add it to the offset of the label itself within the module and then also</p>



<p class="wp-block-paragraph">add that to the the virtual address or I guess the operating system will do the</p>



<p class="wp-block-paragraph">address. But you know, the point is the linker coordinates all the jumps and the conditional</p>



<p class="wp-block-paragraph">branches where the functions start, lays out all the modules, gets all the offsets,</p>



<p class="wp-block-paragraph">and then starts replacing all of the conditional branches and jumps and things with the real</p>



<p class="wp-block-paragraph">offsets that make it actually doable. Like let&#8217;s jump to exactly this memory location</p>



<p class="wp-block-paragraph">in code exactly in quotes, because we&#8217;re still using virtual addressing.</p>



<p class="wp-block-paragraph">idea of the linker it knows how to jump between modules um wants to link or discuss okay that&#8217;s</p>



<p class="wp-block-paragraph">all i really wanted to say don&#8217;t forget if you want a label to be available to jump into or to</p>



<p class="wp-block-paragraph">call as a function from outside the module you got to mark it as global so if i actually wanted</p>



<p class="wp-block-paragraph">somebody to be able to call main finish as a function i just have to mark it as global same</p>



<p class="wp-block-paragraph">thing for some label if i say global some label then now at this point another module could call</p>



<p class="wp-block-paragraph">call this as a function or jump into it probably bad form to not put a return a return statement</p>



<p class="wp-block-paragraph">at this point which means when i&#8217;m calling it up here instead of jump not equal to i probably have</p>



<p class="wp-block-paragraph">to add more complicated logic so i can use a function call that gets jumped around if it is</p>



<p class="wp-block-paragraph">equal but so i&#8217;m not going to go that far right now kind of complicated just for this video</p>



<p class="wp-block-paragraph">and then also of course if you intend to jump somewhere else remember that you have to mark</p>



<p class="wp-block-paragraph">So let&#8217;s say there&#8217;s a function in your other module, your C++ module or your C module or your assembly module.</p>



<p class="wp-block-paragraph">You just have to mark it as extern in the text section, in the text segment, like some other function somewhere else, something like that.</p>



<p class="wp-block-paragraph">And then once I do that, now I could actually call it, I could say, call, you know, this.</p>



<p class="wp-block-paragraph">Actually, that&#8217;ll never get reached because the jump equal thing is at the bottom.</p>



<p class="wp-block-paragraph">equal thing is at the bottom but I could do this I could say call it if it was actually a function</p>



<p class="wp-block-paragraph">or I could say jump if it was just a jump point or I could say you know jump not equal to</p>



<p class="wp-block-paragraph">the other function instead of some label something like that so lots of stuff you can do and now you</p>



<p class="wp-block-paragraph">kind of understand the idea of linking is taking all the modules stuffing them inside of the final</p>



<p class="wp-block-paragraph">executable and also putting data inside of the final executable you know like if you&#8217;re creating</p>



<p class="wp-block-paragraph">So, you know, like if you&#8217;re creating a string variable in your globals area of your assembly</p>



<p class="wp-block-paragraph">program or hard coding, any kind of string anywhere in your C++, then it&#8217;s got to be</p>



<p class="wp-block-paragraph">inside of the executable.</p>



<p class="wp-block-paragraph">Otherwise, it wouldn&#8217;t be anywhere when we ran the program.</p>



<p class="wp-block-paragraph">So, yeah, it sticks the data in there.</p>



<p class="wp-block-paragraph">It sticks the segments in there.</p>



<p class="wp-block-paragraph">It, you know, calculates the jumps and all that stuff.</p>



<p class="wp-block-paragraph">I just want to point out you could put strings in a configuration file.</p>



<p class="wp-block-paragraph">of a vanilla C++ or assembly program you probably are making strings directly in the program.</p>



<p class="wp-block-paragraph">Anyway, so I think that&#8217;s the gist of everything that I really wanted to say about what is the</p>



<p class="wp-block-paragraph">general idea of the linker. Thanks for watching this video I hope you learned a little bit and</p>



<p class="wp-block-paragraph">had some fun. I will see you in the next video. Hey everybody thanks for watching this video again</p>



<p class="wp-block-paragraph">it i do hope you did learn something and have some fun if you could do me a please a small little</p>



<p class="wp-block-paragraph">favor could you please subscribe and follow this channel or these videos or whatever it is you do</p>



<p class="wp-block-paragraph">on the current social media website that you&#8217;re looking at right now it would really mean the</p>



<p class="wp-block-paragraph">world to me and it&#8217;ll help make more videos and grow this community so we&#8217;ll be able to do more</p>



<p class="wp-block-paragraph">videos longer videos better videos or just i&#8217;ll be able to keep making videos in general so please</p>



<p class="wp-block-paragraph">and subscribe. You know, sometimes I&#8217;m sleeping in the middle of the night and I just wake up</p>



<p class="wp-block-paragraph">because I know somebody subscribed or followed. It just wakes me up and I get filled with joy.</p>



<p class="wp-block-paragraph">That&#8217;s exactly what happens every single time. So you could do it as a nice favor to me or you</p>



<p class="wp-block-paragraph">could troll me if you want to just wake me up in the middle of the night, just subscribe</p>



<p class="wp-block-paragraph">and then I&#8217;ll just wake up. I promise that&#8217;s what will happen. Also, if you look at the middle of</p>



<p class="wp-block-paragraph">the screen right now, you should see a QR code, which you can scan in order to go to the website,</p>



<p class="wp-block-paragraph">is also named somewhere at the bottom of this video and it&#8217;ll take you to my main website where</p>



<p class="wp-block-paragraph">you can just kind of like see all the videos I published and the services and tutorials and</p>



<p class="wp-block-paragraph">things that I offer and all that good stuff and uh if you have a suggestion for uh uh clarifications</p>



<p class="wp-block-paragraph">or errata or just future videos that you want to see please leave a comment or if you just want to</p>



<p class="wp-block-paragraph">say hey what&#8217;s up what&#8217;s going on you know just send me a comment whatever I also wake up for</p>



<p class="wp-block-paragraph">I wake up in a cold sweat and I&#8217;m like, it would really mean the world to me.</p>



<p class="wp-block-paragraph">I would really appreciate it.</p>



<p class="wp-block-paragraph">So again, thank you so much for watching this video and enjoy the cool music as I fade into</p>



<p class="wp-block-paragraph">the darkness, which is coming for us all.</p>



<p class="wp-block-paragraph">Thank you.</p>
<p>The post <a href="https://www.NeuralLantern.com/how-linkers-work-linking-code-virtual-memory-and-module-jumps-explained/">How Linkers Work: Linking Code, Virtual Memory, and Module Jumps Explained</a> appeared first on <a href="https://www.NeuralLantern.com">NeuralLantern.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.NeuralLantern.com/how-linkers-work-linking-code-virtual-memory-and-module-jumps-explained/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Master IEEE 754 Floats: Binary to Decimal Guide</title>
		<link>https://www.NeuralLantern.com/master-ieee-754-floats-binary-to-decimal-guide/</link>
					<comments>https://www.NeuralLantern.com/master-ieee-754-floats-binary-to-decimal-guide/#respond</comments>
		
		<dc:creator><![CDATA[mike]]></dc:creator>
		<pubDate>Mon, 05 May 2025 01:50:17 +0000</pubDate>
				<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Conversions]]></category>
		<category><![CDATA[Videos]]></category>
		<category><![CDATA[32-bit float]]></category>
		<category><![CDATA[64-bit float]]></category>
		<category><![CDATA[binary fractions]]></category>
		<category><![CDATA[binary to decimal]]></category>
		<category><![CDATA[computer science]]></category>
		<category><![CDATA[CS tutorial]]></category>
		<category><![CDATA[decimal to binary]]></category>
		<category><![CDATA[exponent bias]]></category>
		<category><![CDATA[floating point numbers]]></category>
		<category><![CDATA[IEEE 754]]></category>
		<category><![CDATA[IEEE 754 explained]]></category>
		<category><![CDATA[number systems]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[scientific notation]]></category>
		<guid isPermaLink="false">https://www.NeuralLantern.com/?p=101</guid>

					<description><![CDATA[<p>Learn IEEE 754 floating-point conversion! Step-by-step guide for 32-bit &#038; 64-bit floats, from decimal to binary. Perfect for CS students!</p>
<p>The post <a href="https://www.NeuralLantern.com/master-ieee-754-floats-binary-to-decimal-guide/">Master IEEE 754 Floats: Binary to Decimal Guide</a> appeared first on <a href="https://www.NeuralLantern.com">NeuralLantern.com</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<figure class="wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
<iframe loading="lazy" title="Master IEEE 754 Floats: Binary to Decimal Guide" width="1380" height="776" src="https://www.youtube.com/embed/pjDw2kBzSpI?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
</div></figure>



<p class="wp-block-paragraph">Hey there! Ready to crack the code on IEEE 754 floating-point numbers? In this video, I break down how to convert decimals to binary and back for 32-bit and 64-bit floats with clear, easy-to-follow steps. From scientific notation to biasing exponents, I’ve got you covered with examples (like 45.84375!). Perfect for computer science students, programmers, or anyone curious about how computers store fractions. Pause, rewind, and learn at your pace! Subscribe for more, check my other videos, and drop a comment with your thoughts!</p>



<p class="wp-block-paragraph">Introduction to IEEE 754 00:00:00<br>Prerequisites for Understanding 00:01:03<br>Steps to Convert Decimal to IEEE 754 00:02:31<br>Bias and Exponent Explanation 00:03:17<br>32-bit Float Layout 00:04:09<br>Sign Bit and Fraction Bits 00:05:44<br>Example: Decimal to 32-bit Float 00:07:56<br>Converting 45.84375 to Binary 00:08:34<br>Scientific Notation for Binary 00:09:05<br>Biasing the Exponent 00:10:26<br>Placing Bits in Layout 00:11:17<br>Final 32-bit Float Representation 00:13:32<br>Example: IEEE 754 to Decimal 00:14:28<br>Extracting Sign, Exponent, Fraction 00:15:36<br>Unbiasing Exponent and Reconstructing 00:16:23<br>Converting Binary to Decimal 00:18:53<br>Introduction to 64-bit Floats 00:19:47<br>64-bit Float Layout and Bias 00:20:05<br>Example: 64-bit Float to Decimal 00:21:09<br>Processing 64-bit Float Bits 00:22:05<br>Reconstructing 64-bit Scientific Notation 00:23:26<br>Final Decimal Conversion for 64-bit 00:25:00<br>Conclusion and Recap 00:25:54<br>Call to Subscribe and Outro 00:26:36</p>



<p class="wp-block-paragraph">Thanks for watching!</p>



<p class="wp-block-paragraph">Find us on other social media here:</p>



<ul class="wp-block-list">
<li>https://www.NeuralLantern.com/social</li>
</ul>



<p class="wp-block-paragraph">Please help support us!</p>



<ul class="wp-block-list">
<li>Subscribing + Sharing on Social Media</li>



<li>Leaving a comment or suggestion</li>



<li>Subscribing to our Blog</li>



<li>Watching the main &#8220;pinned&#8221; video of this channel for offers and extras</li>
</ul>



<p class="wp-block-paragraph">Hey there! Let&#8217;s talk about IEEE 754 floating point numbers stored inside of your machine.</p>



<p class="wp-block-paragraph">What the heck am I even talking about? Well, uh, there&#8217;s a standard called IEEE 754 which governs</p>



<p class="wp-block-paragraph">how floating point numbers are stored inside of your computer on x8664 machines. So, you know,</p>



<p class="wp-block-paragraph">of watching this video you probably already know how to convert binary back and forth you know</p>



<p class="wp-block-paragraph">between binary and decimal and hopefully you understand how to do binary with fractions</p>



<p class="wp-block-paragraph">if you don&#8217;t i have other videos i&#8217;ll talk about that in a second and you also understand</p>



<p class="wp-block-paragraph">that in the machine there is like a slightly different format that&#8217;s my doggy slightly</p>



<p class="wp-block-paragraph">different format for storing signed integers in the machine okay so floating point numbers have</p>



<p class="wp-block-paragraph">an even different uh format that we have to follow and the hardware is designed that way</p>



<p class="wp-block-paragraph">hardware is designed that way so before we can really benefit you&#8217;re all gonna</p>



<p class="wp-block-paragraph">see how bad I spell okay before we can benefit from this video your prerequisite</p>



<p class="wp-block-paragraph">knowledge should be that for starters you should be able to convert back and</p>



<p class="wp-block-paragraph">forth between binary and decimal including numbers with fractions so if</p>



<p class="wp-block-paragraph">if you don&#8217;t know how to do that yet this video is is not for you just yet you</p>



<p class="wp-block-paragraph">should go check out my other videos I explain in other videos exactly how to</p>



<p class="wp-block-paragraph">do that go to the other videos come back and then check this one out after you</p>



<p class="wp-block-paragraph">know how to convert back and forth between binary and decimal with</p>



<p class="wp-block-paragraph">fractions the second thing you should know how to do before watching this</p>



<p class="wp-block-paragraph">video is convert binary numbers with fractions to scientific notation and</p>



<p class="wp-block-paragraph">and back again. Meaning you should understand scientific notation and you should also understand</p>



<p class="wp-block-paragraph">how to take a binary number with a fraction and convert it to scientific notation and then</p>



<p class="wp-block-paragraph">convert it or deconvert it back to like regular form. Again, I have another video for this,</p>



<p class="wp-block-paragraph">so if you don&#8217;t know how to do that yet, you should probably pause this video and then go</p>



<p class="wp-block-paragraph">Let&#8217;s see. For converting from a regular number to IEEE floating point number in the machine using just binary alone is the following.</p>



<p class="wp-block-paragraph">So I&#8217;m going to say basic steps. Step one, convert the decimal number to binary if needed.</p>



<p class="wp-block-paragraph">And I say if needed because I don&#8217;t know, maybe you started with a binary number so you don&#8217;t actually need to convert it.</p>



<p class="wp-block-paragraph">it but I&#8217;m just going to assume that you have a decimal number so you&#8217;re going to convert it to</p>



<p class="wp-block-paragraph">binary first then convert the binary number to scientific notation I don&#8217;t know if convert is</p>



<p class="wp-block-paragraph">the right word here because we&#8217;re not actually changing the value of the number we&#8217;re just</p>



<p class="wp-block-paragraph">changing the representation so convert it to a scientific notation form maybe would be better</p>



<p class="wp-block-paragraph">step three we&#8217;ll add a bias to the exponents of the scientific notation form what do I mean by</p>



<p class="wp-block-paragraph">notation form. What do I mean by that? You know, if you have like a binary number and it&#8217;s in</p>



<p class="wp-block-paragraph">scientific notation format, it&#8217;s going to look like this. I liked when I&#8217;m doing IEEE 754,</p>



<p class="wp-block-paragraph">I like to keep the right side of the number in decimal. I&#8217;m sorry if this confuses you, but</p>



<p class="wp-block-paragraph">it&#8217;s not really necessary to convert this to binary when we&#8217;re just trying to convert back</p>



<p class="wp-block-paragraph">and forth between IEEE. So I always say two to the something power rather than one zero to the</p>



<p class="wp-block-paragraph">something power because I want to stay in decimal. So I&#8217;ll say, you know, two to the seventh power,</p>



<p class="wp-block-paragraph">right? What this means is that seven is the exponent and I have to bias the exponent before</p>



<p class="wp-block-paragraph">I put it into the machine. So maybe it&#8217;s worth understanding or maybe copy pasting right now</p>



<p class="wp-block-paragraph">that the bias for 32-bit floating point numbers, I should probably, I&#8217;ll paste the whole thing here.</p>



<p class="wp-block-paragraph">Okay. So here&#8217;s like the format for a 32-bit floating point number. We&#8217;re good about this</p>



<p class="wp-block-paragraph">number. We&#8217;re good about this just for a second. The bias for 32-bit floating</p>



<p class="wp-block-paragraph">point number in IEEE 754 is 127. So that means I pretty much have to just take</p>



<p class="wp-block-paragraph">the number 7 and bias it by adding 127 to it. After I&#8217;ve done that I can convert</p>



<p class="wp-block-paragraph">the biased exponent to unsigned binary whole number. To an unsigned binary whole</p>



<p class="wp-block-paragraph">number. So step four here is just regular decimal to binary conversion. So I would take, you know,</p>



<p class="wp-block-paragraph">seven plus 127. The result of that, which I think is like 134, maybe we&#8217;ll just be converted into</p>



<p class="wp-block-paragraph">binary and unsigned binary integer, not two&#8217;s compliment or anything like that. Then step five</p>



<p class="wp-block-paragraph">is respect the layout. So I just, I just copy pasted the layout up above and the layout is this.</p>



<p class="wp-block-paragraph">you can see that here let me see if I just maybe paste this down at the bottom</p>



<p class="wp-block-paragraph">you can see that we actually have 32 bits here if I count them for you real</p>



<p class="wp-block-paragraph">fast we&#8217;ve got one for the sign and then we&#8217;ve got I can never remember this I</p>



<p class="wp-block-paragraph">think it&#8217;s eight for the exponent one two three four five six seven eight got</p>



<p class="wp-block-paragraph">eight bits for the exponent that means I&#8217;ve already used nine of 32 bits so</p>



<p class="wp-block-paragraph">that means I should have like 23 bits here so one two three four five six seven</p>



<p class="wp-block-paragraph">11, 12, 13, 15, 16, 17, 18, 19, 20, 21, 22, 23, just to double check.</p>



<p class="wp-block-paragraph">So we know what the sine bit is.</p>



<p class="wp-block-paragraph">Actually, we don&#8217;t yet know in this video.</p>



<p class="wp-block-paragraph">So in this video, the sine bit, it&#8217;s always going to be a zero if the number is positive</p>



<p class="wp-block-paragraph">and a one if the number is negative.</p>



<p class="wp-block-paragraph">So that&#8217;s the sine bit.</p>



<p class="wp-block-paragraph">The biased exponent bits go there.</p>



<p class="wp-block-paragraph">And then these Fs, those are just the fractional bits.</p>



<p class="wp-block-paragraph">just the, you know, like the mantissa or the mantissa part of the fraction. So imagine if we</p>



<p class="wp-block-paragraph">have a number like this, all I&#8217;m saying is we would copy paste those numbers right here.</p>



<p class="wp-block-paragraph">Notice how I&#8217;m ignoring that first one dot something, because when you put binary in</p>



<p class="wp-block-paragraph">scientific notation, the first number is always going to be a one. So it can be assumed. There&#8217;s</p>



<p class="wp-block-paragraph">no point in storing it inside the machine. And then if you don&#8217;t have enough digits to</p>



<p class="wp-block-paragraph">you will literally just pad with zeros on the right side because padding with zeros on the right side of a fraction</p>



<p class="wp-block-paragraph">doesn&#8217;t actually change the value. One, two, three, four.</p>



<p class="wp-block-paragraph">If I put the zeros on the left side of the fraction, it would make the fractional part smaller and smaller.</p>



<p class="wp-block-paragraph">So that would be bad. I don&#8217;t want to change the value.</p>



<p class="wp-block-paragraph">And this is the opposite of how you pad a whole number.</p>



<p class="wp-block-paragraph">If I put numbers on the left side of a whole number part, I&#8217;m not changing the value.</p>



<p class="wp-block-paragraph">But if I put numbers on the right side of a whole number part,</p>



<p class="wp-block-paragraph">which in this case would be the biased exponent, then I would be changing the value.</p>



<p class="wp-block-paragraph">So we wouldn&#8217;t want to do that.</p>



<p class="wp-block-paragraph">changing the value so we wouldn&#8217;t want to do that. Anyway I&#8217;m going to remove this and just stick</p>



<p class="wp-block-paragraph">with step five so let&#8217;s see 5a is place the sine bits step 5b is and I&#8217;m going to do an example</p>



<p class="wp-block-paragraph">for you don&#8217;t worry place the exponent bits and then 5c is place the fraction bits everything</p>



<p class="wp-block-paragraph">the first one dot from scientific notation form.</p>



<p class="wp-block-paragraph">Again, because the first one is implied, it will never be a zero if you&#8217;ve done it correctly.</p>



<p class="wp-block-paragraph">If you end up with a binary number that looks like this in scientific notation, then you&#8217;ve</p>



<p class="wp-block-paragraph">done something wrong because the first number is supposed to be a one.</p>



<p class="wp-block-paragraph">Okay, so we have those basic steps.</p>



<p class="wp-block-paragraph">And now let&#8217;s do an example.</p>



<p class="wp-block-paragraph">1, 2, 3 example. Let&#8217;s convert decimal to IEEE 754 32-bit float format.</p>



<p class="wp-block-paragraph">AKA single precision floating point number. Double precision floating point number is 64-bit.</p>



<p class="wp-block-paragraph">We&#8217;ll do an example for that at the very end of this, but I&#8217;m just going to stick with 32 and do</p>



<p class="wp-block-paragraph">number 45.84375, just double checking, and then we&#8217;ll convert to binary. Again, this knowledge</p>



<p class="wp-block-paragraph">is contained in a different video. So if you don&#8217;t know how to do this yet, you&#8217;ll need to go see my</p>



<p class="wp-block-paragraph">other video. And so you can see it&#8217;s, you know, 45.84375 in binary is just going to be this.</p>



<p class="wp-block-paragraph">I&#8217;ve padded it with two zeros to the left just because, I don&#8217;t know, I have a habit of wanting</p>



<p class="wp-block-paragraph">wanting everything to look like it&#8217;s inside of 8-bit chunks.</p>



<p class="wp-block-paragraph">You can see there&#8217;s 8 bits here.</p>



<p class="wp-block-paragraph">But really, I can just remove those first two numbers.</p>



<p class="wp-block-paragraph">It doesn&#8217;t matter.</p>



<p class="wp-block-paragraph">Convert the number to binary.</p>



<p class="wp-block-paragraph">Then, I have to convert the binary number to scientific notation.</p>



<p class="wp-block-paragraph">I&#8217;m going to put maybe pseudo-scientific notation</p>



<p class="wp-block-paragraph">because I&#8217;m not going to convert the right part</p>



<p class="wp-block-paragraph">where it&#8217;s the exponent into binary.</p>



<p class="wp-block-paragraph">I&#8217;m going to keep it in decimal.</p>



<p class="wp-block-paragraph">Just to clarify again,</p>



<p class="wp-block-paragraph">convert a binary number to scientific notation and you were actually going to publish it somewhere</p>



<p class="wp-block-paragraph">or give it to someone, then you should convert the right side. It&#8217;s just that I&#8217;m not going to</p>



<p class="wp-block-paragraph">because I don&#8217;t really need to convert the right side. I&#8217;m not interested in having the whole</p>



<p class="wp-block-paragraph">number in scientific notation in binary. I&#8217;m just interested in what the fractional bits are and</p>



<p class="wp-block-paragraph">then what the exponent is going to do. Like how many positions to the left or right is it actually</p>



<p class="wp-block-paragraph">going to move the decimal point? And that&#8217;s just going to be the number five, five times to the</p>



<p class="wp-block-paragraph">five you know five times to the left or to the right so I&#8217;m gonna go pseudo</p>



<p class="wp-block-paragraph">scientific notation you pretty much you know as I covered in the different video</p>



<p class="wp-block-paragraph">all we&#8217;re gonna be doing is just moving the decimal point over one two three</p>



<p class="wp-block-paragraph">four five until there&#8217;s a one in the leading spot and then account for it by</p>



<p class="wp-block-paragraph">saying times two to the fifth power to say the number is a lot bigger than it</p>



<p class="wp-block-paragraph">looks so that&#8217;s that and let&#8217;s see if there are any trailing zeros that&#8217;s</p>



<p class="wp-block-paragraph">Let&#8217;s see if there are any trailing zeros, that&#8217;s okay on the right side of the fraction.</p>



<p class="wp-block-paragraph">They don&#8217;t actually matter.</p>



<p class="wp-block-paragraph">You can also just delete them if you want.</p>



<p class="wp-block-paragraph">Then we need to bias the exponents.</p>



<p class="wp-block-paragraph">So how do we bias the exponent?</p>



<p class="wp-block-paragraph">The exponent is just the number five.</p>



<p class="wp-block-paragraph">That&#8217;s see, I was telling you like I don&#8217;t really care to convert it to binary because</p>



<p class="wp-block-paragraph">I&#8217;m just going to bias it first and then after that I&#8217;ll buy it or I&#8217;ll convert it to binary.</p>



<p class="wp-block-paragraph">So biasing it is just basically adding the bias.</p>



<p class="wp-block-paragraph">just to make sure that it&#8217;s on this page and it&#8217;s easy to see.</p>



<p class="wp-block-paragraph">So I&#8217;ll do that.</p>



<p class="wp-block-paragraph">So in the 32-bit float layout, the bias is 127.</p>



<p class="wp-block-paragraph">So I&#8217;m going to add 127 to 5.</p>



<p class="wp-block-paragraph">The final number is going to be 132.</p>



<p class="wp-block-paragraph">So that&#8217;s the biased exponent now.</p>



<p class="wp-block-paragraph">Then I convert the biased exponent to binary.</p>



<p class="wp-block-paragraph">And that&#8217;s going to be this.</p>



<p class="wp-block-paragraph">10000100.</p>



<p class="wp-block-paragraph">Then set up the layout so you don&#8217;t get confused.</p>



<p class="wp-block-paragraph">This step is crucial.</p>



<p class="wp-block-paragraph">Everyone always gets confused by the layout because like we&#8217;re human beings.</p>



<p class="wp-block-paragraph">I can&#8217;t count 32 zeros that are all like in the same area and like, you know, and not</p>



<p class="wp-block-paragraph">get confused every single time.</p>



<p class="wp-block-paragraph">I mean, I guess I won&#8217;t get confused half the time, but that&#8217;s not good enough.</p>



<p class="wp-block-paragraph">So step one is place the layout for yourself so it&#8217;s easier for you to place the bits.</p>



<p class="wp-block-paragraph">place the bits and I wrote this at the top 8 bits and 23 bits just as a reminder double check</p>



<p class="wp-block-paragraph">yourself 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 that&#8217;s 23 bits 1 2 3 4 1 2 3 4 that&#8217;s</p>



<p class="wp-block-paragraph">8 bits we don&#8217;t need to remember that the sign bit is one bit for now it&#8217;s not too hard so now</p>



<p class="wp-block-paragraph">let&#8217;s place it so the first thing to note is that this number was actually positive positive is</p>



<p class="wp-block-paragraph">the negative sign there, but if it makes you feel better, we&#8217;ll just put a positive sign there just to clarify and be specific.</p>



<p class="wp-block-paragraph">So because the number is positive, the sign bit is going to be zero. If it were negative, it would be one.</p>



<p class="wp-block-paragraph">Then we will put the biased exponent bits. So we already converted up there. So I&#8217;m just going to copy paste it here.</p>



<p class="wp-block-paragraph">We&#8217;re pretty lucky that the bits are just as big as the number of biased exponent bits that are available.</p>



<p class="wp-block-paragraph">But suppose for the sake of argument that we had,</p>



<p class="wp-block-paragraph">the sake of argument that we had just like you know this small number here for the biased exponent</p>



<p class="wp-block-paragraph">what would you do with the remaining spaces you would just pad with zeros to the left</p>



<p class="wp-block-paragraph">because remember in whole numbers in binary and decimal you pad to the left you&#8217;re not actually</p>



<p class="wp-block-paragraph">changing the value you definitely would not want to pad to the right but you got to put</p>



<p class="wp-block-paragraph">a bit in every position it&#8217;s got to be something so i&#8217;m just going to pad with zeros</p>



<p class="wp-block-paragraph">then we take the fractional part from the scientifically notated form so that&#8217;s just</p>



<p class="wp-block-paragraph">form so that&#8217;s just this right here notice how I&#8217;m copy pasting every bit</p>



<p class="wp-block-paragraph">except for the one that starts the number I&#8217;m not going to do the one dot</p>



<p class="wp-block-paragraph">part because that&#8217;s always assumed so we don&#8217;t need to store it it wouldn&#8217;t make</p>



<p class="wp-block-paragraph">sense I&#8217;ll copy paste the fractional part and I&#8217;ll just stick it down there</p>



<p class="wp-block-paragraph">and now we have a bunch of leftover bits that we need to fill out with the</p>



<p class="wp-block-paragraph">fractional part you pad to the right not to the left so I&#8217;m just going to put</p>



<p class="wp-block-paragraph">zeros to the right because that won&#8217;t change the value of the fractional part</p>



<p class="wp-block-paragraph">Now we&#8217;ve got it. I&#8217;m just going to double check my work here.</p>



<p class="wp-block-paragraph">Oh gosh, it&#8217;s too hard to read and then a bunch of zeros. Okay.</p>



<p class="wp-block-paragraph">Then remove these spaces because now that you&#8217;ve done your layout,</p>



<p class="wp-block-paragraph">you actually want to bear in mind that the machine doesn&#8217;t have spaces.</p>



<p class="wp-block-paragraph">The machine is just, you know, a bunch of ones and zeros everywhere.</p>



<p class="wp-block-paragraph">So I&#8217;m just going to carefully remove the two spaces.</p>



<p class="wp-block-paragraph">And this is it.</p>



<p class="wp-block-paragraph">for floating point representation of the number of the decimal number positive 45.84375</p>



<p class="wp-block-paragraph">seems like a lot but it&#8217;s not too bad once you kind of get used to the format</p>



<p class="wp-block-paragraph">and the bias and you already know the other steps of you know converting decimal to binary and back</p>



<p class="wp-block-paragraph">again so let&#8217;s do another number let&#8217;s do it backwards so i&#8217;m going to open up a new tab here</p>



<p class="wp-block-paragraph">example, IEEE 754 32-bit float 2 decimal.</p>



<p class="wp-block-paragraph">Okay, so suppose we started with the following number.</p>



<p class="wp-block-paragraph">Start with this number.</p>



<p class="wp-block-paragraph">Oh my gosh, right?</p>



<p class="wp-block-paragraph">Remember the layout.</p>



<p class="wp-block-paragraph">So in the layout we have, use the layout.</p>



<p class="wp-block-paragraph">Maybe I should copy paste the layout again one more time just to make sure that it&#8217;s</p>



<p class="wp-block-paragraph">easy to see.</p>



<p class="wp-block-paragraph">it&#8217;s easy to see. So I&#8217;m going to paste it up at the top and well, no, maybe I want this because</p>



<p class="wp-block-paragraph">this is like a little bit better. I want that version. Okay. So 32 bits, a bias of 127. So</p>



<p class="wp-block-paragraph">we&#8217;re going to use the layout. I&#8217;m just going to copy paste the original number and then add</p>



<p class="wp-block-paragraph">spaces because I know, well, I guess I can copy paste the layout itself right above that number.</p>



<p class="wp-block-paragraph">I know I need a space right there that&#8217;s the sine bit and then I need a space</p>



<p class="wp-block-paragraph">after that and notice how the numbers all line up so there&#8217;s nothing missing</p>



<p class="wp-block-paragraph">just to double-check yourself okay so I have the layout I know right away that</p>



<p class="wp-block-paragraph">the number is going to be positive because the sine bit is zero sign is</p>



<p class="wp-block-paragraph">positive okay so then I need to pull the biased exponent will be biased</p>



<p class="wp-block-paragraph">the exponent bits only so I&#8217;m just going to copy paste those bits and then I&#8217;ll</p>



<p class="wp-block-paragraph">pull out the fractional part first pull out the fractional part I&#8217;m going to</p>



<p class="wp-block-paragraph">copy paste all those bits and maybe I&#8217;ll just say zero point those bits because</p>



<p class="wp-block-paragraph">that&#8217;s what I originally grabbed and I can delete all the zeros on the right</p>



<p class="wp-block-paragraph">side because again that won&#8217;t change the value of the fractional part so I&#8217;m</p>



<p class="wp-block-paragraph">going to delete make sure you&#8217;re only deleting zeros though delete that now I</p>



<p class="wp-block-paragraph">I need to unbias the biased exponents.</p>



<p class="wp-block-paragraph">First, actually, I should, well, let&#8217;s convert the biased exponent to decimal.</p>



<p class="wp-block-paragraph">A little easier.</p>



<p class="wp-block-paragraph">I guess you don&#8217;t have to do that, but it&#8217;s a little easier for me.</p>



<p class="wp-block-paragraph">Pull the biased exponent.</p>



<p class="wp-block-paragraph">So this number is going to be 132, which I think is what we had last night.</p>



<p class="wp-block-paragraph">Let me just double check that.</p>



<p class="wp-block-paragraph">132.</p>



<p class="wp-block-paragraph">Yeah.</p>



<p class="wp-block-paragraph">132, yeah so the biased exponent that we pulled out is 132 then we unbiased the</p>



<p class="wp-block-paragraph">biased exponent so just subtract the bias again in 32-bit format here the bias</p>



<p class="wp-block-paragraph">is 127 so I&#8217;m going to subtract 127 instead of adding 127 so now I know the</p>



<p class="wp-block-paragraph">real bias or sorry I know the real exponent is 5 then I can recreate the</p>



<p class="wp-block-paragraph">I&#8217;ll put sudo here just because it&#8217;s not, you know, I&#8217;m not, I&#8217;m not converting binary for,</p>



<p class="wp-block-paragraph">for the entire thing. So that means I can take the fractional part here and I can say it&#8217;s going to be</p>



<p class="wp-block-paragraph">one dot the fractional part. Maybe I should remove that zero here to make it less.</p>



<p class="wp-block-paragraph">I don&#8217;t know. Cause if I put a one there, it kind of feels like I&#8217;m saying the number is</p>



<p class="wp-block-paragraph">that it&#8217;s one dot something.</p>



<p class="wp-block-paragraph">I don&#8217;t like that I&#8217;m putting a zero there.</p>



<p class="wp-block-paragraph">I&#8217;m just gonna erase it</p>



<p class="wp-block-paragraph">because it&#8217;s really gonna end up being a one.</p>



<p class="wp-block-paragraph">And if I say pull the fractional part</p>



<p class="wp-block-paragraph">and I put a one there,</p>



<p class="wp-block-paragraph">then it doesn&#8217;t it kind of sound like</p>



<p class="wp-block-paragraph">I&#8217;m pulling the one from somewhere?</p>



<p class="wp-block-paragraph">No, the one is implied.</p>



<p class="wp-block-paragraph">Anyway, so now I can recreate the number</p>



<p class="wp-block-paragraph">in pseudo scientific notation.</p>



<p class="wp-block-paragraph">I can say times two to the something power.</p>



<p class="wp-block-paragraph">We know that the exponent is five.</p>



<p class="wp-block-paragraph">Again, it&#8217;s pseudo scientific notation</p>



<p class="wp-block-paragraph">because if five we&#8217;re gonna do the complete,</p>



<p class="wp-block-paragraph">complete, you know, true scientific notation. The right side should also be in binary, but I&#8217;m not</p>



<p class="wp-block-paragraph">going to do it. I&#8217;m a little bit lazy because we don&#8217;t need that IEEE. So it&#8217;s going to be two to</p>



<p class="wp-block-paragraph">the fifth power. Then if I undo the scientific notation, I&#8217;m really just going to take this</p>



<p class="wp-block-paragraph">scientifically notated version and I&#8217;m going to say, well, I&#8217;m going to move the decimal point to</p>



<p class="wp-block-paragraph">the right five times because that&#8217;s what the part on the right says. So I&#8217;m going to go one, two,</p>



<p class="wp-block-paragraph">1, 2, 3, 4, 5, stick it there, remove the original decimal point, and then I can remove</p>



<p class="wp-block-paragraph">the exponent part. So then let me just double check my work. 1, 0, 1, 1, 0, 1, 1, 1, 0, 1. Okay.</p>



<p class="wp-block-paragraph">So we&#8217;ve got that now. Then all we have to do is convert this number from binary to decimal.</p>



<p class="wp-block-paragraph">The final number here is just, you know, it&#8217;s going to be the same number that we worked with</p>



<p class="wp-block-paragraph">number that we worked with previously so I&#8217;m just going to copy paste it there is</p>



<p class="wp-block-paragraph">you know of course this video is not about converting back and forth from</p>



<p class="wp-block-paragraph">binary to decimal with fractions check out my other video if you want to learn</p>



<p class="wp-block-paragraph">how to do that but once we do that you know this number becomes that number</p>



<p class="wp-block-paragraph">and and now we know how to convert back and forth between a decimal number and</p>



<p class="wp-block-paragraph">for 32-bit floats in the machine.</p>



<p class="wp-block-paragraph">No problem.</p>



<p class="wp-block-paragraph">A lot of steps, but no problem once you understand them.</p>



<p class="wp-block-paragraph">Okay, now let&#8217;s do an example</p>



<p class="wp-block-paragraph">with 64-bit floating point numbers.</p>



<p class="wp-block-paragraph">Honestly, this is not gonna be more difficult.</p>



<p class="wp-block-paragraph">In 64-bit floats, the idea and the format and the steps,</p>



<p class="wp-block-paragraph">it&#8217;s all gonna be the exact same thing.</p>



<p class="wp-block-paragraph">It&#8217;s just that we have more bits</p>



<p class="wp-block-paragraph">for the biased exponent and the fraction,</p>



<p class="wp-block-paragraph">and then the bias itself will be a little bit higher.</p>



<p class="wp-block-paragraph">So let me copy paste the format for you to see.</p>



<p class="wp-block-paragraph">at for you to see. So in IEEE 64-bit floats, IEEE 64-bit float, well IEEE 754, 64-bit float,</p>



<p class="wp-block-paragraph">you know we refer to these floats as doubles right double precision floating point numbers.</p>



<p class="wp-block-paragraph">Notice how instead of 8 bits for the biased exponent we have 11 so we can represent a much</p>



<p class="wp-block-paragraph">notice how for the uh the fraction part instead of having 23 bits we have 52 bits so we can also</p>



<p class="wp-block-paragraph">represent much more precisely that&#8217;s really the only difference let&#8217;s uh oh sorry the other</p>



<p class="wp-block-paragraph">difference is also that the bias is now equal to 1023 instead of 127 so what is that like</p>



<p class="wp-block-paragraph">10 times larger of a number that we can represent or something like that so mostly we get more</p>



<p class="wp-block-paragraph">If you don&#8217;t like it, sorry, it&#8217;s the way it is.</p>



<p class="wp-block-paragraph">It&#8217;s in the hardware.</p>



<p class="wp-block-paragraph">So let&#8217;s do an example for a 64-bit float for a double.</p>



<p class="wp-block-paragraph">64-bit example.</p>



<p class="wp-block-paragraph">Let&#8217;s say we started with the following number.</p>



<p class="wp-block-paragraph">Inside of the machine.</p>



<p class="wp-block-paragraph">Like we looked inside of the machine and we grabbed these bits.</p>



<p class="wp-block-paragraph">And I&#8217;ll get rid of the spaces.</p>



<p class="wp-block-paragraph">So we have like a giant, big, huge number.</p>



<p class="wp-block-paragraph">We have like a giant big huge number.</p>



<p class="wp-block-paragraph">We&#8217;re trying to figure out, you know, what is this number in decimal.</p>



<p class="wp-block-paragraph">So I&#8217;m going to add spaces to respect the layout.</p>



<p class="wp-block-paragraph">I&#8217;m going to just copy paste the layout right here.</p>



<p class="wp-block-paragraph">I&#8217;m going to say respect the layout.</p>



<p class="wp-block-paragraph">I&#8217;m going to paste it and then that helps me line everything up.</p>



<p class="wp-block-paragraph">So I&#8217;m going to say the sine bit is the first bit and then I&#8217;ll put a space there so I know.</p>



<p class="wp-block-paragraph">All right, the sine bit is a one.</p>



<p class="wp-block-paragraph">That means it&#8217;s going to be a negative number.</p>



<p class="wp-block-paragraph">The biased exponent bits are there.</p>



<p class="wp-block-paragraph">The fractional bits are there.</p>



<p class="wp-block-paragraph">bits are there so well first thing I can just do is say that the sine is going to be negative</p>



<p class="wp-block-paragraph">because the sine bit is a one</p>



<p class="wp-block-paragraph">and then I&#8217;ll pull the biased exponent bits which is going to be this number right here</p>



<p class="wp-block-paragraph">should pull the fraction bits next. Fraction bits are just here I&#8217;m gonna</p>



<p class="wp-block-paragraph">copy paste those here and then I can remove the zeros. Be very careful you&#8217;re</p>



<p class="wp-block-paragraph">not removing any ones. So there was a lot of wasted bits there. That&#8217;s okay. I&#8217;ll</p>



<p class="wp-block-paragraph">convert the biased exponent to decimal. So that&#8217;s going to be…</p>



<p class="wp-block-paragraph">I think and I did not do that in my head.</p>



<p class="wp-block-paragraph">I have an answer sheet.</p>



<p class="wp-block-paragraph">Don&#8217;t worry.</p>



<p class="wp-block-paragraph">I&#8217;m not that cool.</p>



<p class="wp-block-paragraph">Then we&#8217;ll unbiased or de-bias unbiased the biased exponents by just subtracting the bias.</p>



<p class="wp-block-paragraph">Remember in this 64 bit format, the bias is 1023.</p>



<p class="wp-block-paragraph">So that means I got to take 1031 minus 1023 and that will be equal to 8.</p>



<p class="wp-block-paragraph">Okay.</p>



<p class="wp-block-paragraph">Okay, now we kind of have everything we need to sort of reconstruct the scientific notation part, right?</p>



<p class="wp-block-paragraph">We have the fraction bits, that&#8217;s the most important part.</p>



<p class="wp-block-paragraph">Oh, and then also the sine bits.</p>



<p class="wp-block-paragraph">So I can say negative something.</p>



<p class="wp-block-paragraph">It&#8217;s obviously going to be one dot something because even though the number is negative,</p>



<p class="wp-block-paragraph">it will still always start with a one.</p>



<p class="wp-block-paragraph">That rule doesn&#8217;t change.</p>



<p class="wp-block-paragraph">Negative one dot something and I&#8217;ll just paste the, whoops, paste the fraction bits.</p>



<p class="wp-block-paragraph">I think I did paste the right thing.</p>



<p class="wp-block-paragraph">right thing so we paste the fraction bits and then we have to use the regular exponent the</p>



<p class="wp-block-paragraph">unbiased exponent the non-biased exponent two times times two to the oops times two to the eighth power</p>



<p class="wp-block-paragraph">now this is our number in scientific notation um</p>



<p class="wp-block-paragraph">convert to scientific notation i&#8217;ll put p for pseudo scientific notation</p>



<p class="wp-block-paragraph">and then now we have to convert to just regular format okay so I&#8217;m going to</p>



<p class="wp-block-paragraph">copy paste this right here and if it&#8217;s 2 to the eighth power that means the real</p>



<p class="wp-block-paragraph">number is going to be bigger than it looks in scientific notation even though</p>



<p class="wp-block-paragraph">if you are very familiar with scientific notation you kind of already know that</p>



<p class="wp-block-paragraph">it looks big but you know if we just if we&#8217;re only talking about the bits on the</p>



<p class="wp-block-paragraph">1, 2, 3, 4, 5, 6, 7, 8.</p>



<p class="wp-block-paragraph">Put the decimal point there.</p>



<p class="wp-block-paragraph">Remove the original decimal point.</p>



<p class="wp-block-paragraph">Now we no longer need 2 to the 8th power.</p>



<p class="wp-block-paragraph">And again, just as a reminder, if it was 2 to the negative 8th power,</p>



<p class="wp-block-paragraph">you would be moving the decimal point in the other direction.</p>



<p class="wp-block-paragraph">So now we&#8217;ve got this number 111, 010101, 0101, 0101, 0101.</p>



<p class="wp-block-paragraph">Then a 0.01.</p>



<p class="wp-block-paragraph">Okay, so then convert to decimal.</p>



<p class="wp-block-paragraph">doesn&#8217;t talk about how to convert back and forth from binary to decimal find my other videos but</p>



<p class="wp-block-paragraph">basically uh it&#8217;s going to end up being six uh negative four six nine point two five</p>



<p class="wp-block-paragraph">okay we now have done a quick practice starting with a giant number of bits and slowly converting</p>



<p class="wp-block-paragraph">them to the real uh floating point number in decimal that uh that they represent i&#8217;m not going</p>



<p class="wp-block-paragraph">going to do another number in the reverse direction because we already did that for 32 bits</p>



<p class="wp-block-paragraph">and again with 64 bits the only real difference is just you have more exponent and fraction bits</p>



<p class="wp-block-paragraph">and the bias is a higher number and that&#8217;s it so like all the other steps are just the same</p>



<p class="wp-block-paragraph">I just wanted to show you one time with a 64-bit number in one direction but</p>



<p class="wp-block-paragraph">I think at this point we&#8217;re good thank you so much for watching this video I hope you learned</p>



<p class="wp-block-paragraph">had a little bit of fun. I&#8217;ll see you in the next video.</p>



<p class="wp-block-paragraph">and grow this community so we&#8217;ll be able to do more videos, longer videos, better videos,</p>



<p class="wp-block-paragraph">or just I&#8217;ll be able to keep making videos in general. So please do me a kindness and subscribe.</p>



<p class="wp-block-paragraph">You know, sometimes I&#8217;m sleeping in the middle of the night and I just wake up because I know</p>



<p class="wp-block-paragraph">somebody subscribed or followed. It just wakes me up and I get filled with joy. That&#8217;s exactly what</p>



<p class="wp-block-paragraph">happens every single time. So you could do it as a nice favor to me or you could troll me if you</p>



<p class="wp-block-paragraph">want to just wake me up in the middle of the night, just subscribe and then I&#8217;ll just wake up.</p>



<p class="wp-block-paragraph">just wake up I promise that&#8217;s what will happen also if you look at the middle of</p>



<p class="wp-block-paragraph">the screen right now you should see a QR code which you can scan in order to go</p>



<p class="wp-block-paragraph">to the website which I think is also named somewhere at the bottom of this</p>



<p class="wp-block-paragraph">video and it&#8217;ll take you to my main website where you can just kind of like</p>



<p class="wp-block-paragraph">see all the videos I published and the services and tutorials and things that I</p>



<p class="wp-block-paragraph">offer and all that good stuff and if you have a suggestion for clarifications or</p>



<p class="wp-block-paragraph">or errata or just future videos that you want to see please leave a comment or if you just want to</p>



<p class="wp-block-paragraph">say hey what&#8217;s up what&#8217;s going on you know just send me a comment whatever I also wake up for</p>



<p class="wp-block-paragraph">those in the middle of the night I get I wake up in a cold sweat and I&#8217;m like it would really it</p>



<p class="wp-block-paragraph">really mean the world to me I would really appreciate it so again thank you so much for</p>



<p class="wp-block-paragraph">watching this video and um enjoy the cool music as as I fade into the darkness which is coming for us</p>



<p class="wp-block-paragraph">Thank you.</p>
<p>The post <a href="https://www.NeuralLantern.com/master-ieee-754-floats-binary-to-decimal-guide/">Master IEEE 754 Floats: Binary to Decimal Guide</a> appeared first on <a href="https://www.NeuralLantern.com">NeuralLantern.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.NeuralLantern.com/master-ieee-754-floats-binary-to-decimal-guide/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to Master Binary Scientific Notation (with Fun Examples!)</title>
		<link>https://www.NeuralLantern.com/how-to-master-binary-scientific-notation-with-fun-examples/</link>
					<comments>https://www.NeuralLantern.com/how-to-master-binary-scientific-notation-with-fun-examples/#respond</comments>
		
		<dc:creator><![CDATA[mike]]></dc:creator>
		<pubDate>Sun, 04 May 2025 06:24:32 +0000</pubDate>
				<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Conversions]]></category>
		<category><![CDATA[Videos]]></category>
		<category><![CDATA[base-2 notation]]></category>
		<category><![CDATA[binary fractions]]></category>
		<category><![CDATA[binary math]]></category>
		<category><![CDATA[binary numbers]]></category>
		<category><![CDATA[binary scientific notation]]></category>
		<category><![CDATA[coding for beginners]]></category>
		<category><![CDATA[computer science]]></category>
		<category><![CDATA[decimal to binary]]></category>
		<category><![CDATA[floating-point representation]]></category>
		<category><![CDATA[IEEE 754]]></category>
		<category><![CDATA[number systems]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[scientific notation]]></category>
		<category><![CDATA[tech tutorials]]></category>
		<guid isPermaLink="false">https://www.NeuralLantern.com/?p=99</guid>

					<description><![CDATA[<p>Master binary scientific notation with this fun, beginner-friendly guide! Learn to represent binary numbers with fractions for IEEE 754 and computer science. Clear examples show how to handle large and small numbers in base-2. Perfect for students and coders! Subscribe for more tech tutorials.</p>
<p>The post <a href="https://www.NeuralLantern.com/how-to-master-binary-scientific-notation-with-fun-examples/">How to Master Binary Scientific Notation (with Fun Examples!)</a> appeared first on <a href="https://www.NeuralLantern.com">NeuralLantern.com</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<figure class="wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
<iframe loading="lazy" title="How to Master Binary Scientific Notation (with Fun Examples!)" width="1380" height="776" src="https://www.youtube.com/embed/GJKxf_-MZiY?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
</div></figure>



<p class="wp-block-paragraph">Ready to conquer binary scientific notation? Let’s make it fun and simple! In this video, I walk you through how to represent binary numbers with fractions in scientific notation—a must-know skill for computer science, programming, and understanding IEEE 754 floating-point representation. We start with the basics of scientific notation in decimal (think 8.54 × 10⁵), then dive into binary with clear, step-by-step examples. You’ll learn how to handle large and small binary numbers, move decimal points, and use base-2 like a champ. Whether you’re a student, coder, or just curious about how computers process numbers, this video has you covered!</p>



<p class="wp-block-paragraph">I’ll show you practical examples, like converting huge binary numbers and tiny fractions, plus tips to avoid common mistakes (like mixing decimal and binary notation). By the end, you’ll be ready to tackle binary in IEEE 754 or impress your friends with your number-crunching skills. Subscribe for more tech tutorials, and hit that bell to stay updated! Visit my website (link below) for more resources, and leave a comment with your questions or video suggestions—I read every one! Let’s keep learning and having fun with tech together!</p>



<p class="wp-block-paragraph">Introduction to Binary Scientific Notation 00:00:00<br>Purpose of Binary Representation 00:00:12<br>Overview of Scientific Notation 00:00:41<br>Rules for Scientific Notation 00:01:12<br>Decimal Scientific Notation Example 00:02:26<br>Practice with Large Decimal Number 00:04:12<br>Practice with Small Decimal Number 00:05:21<br>Binary Scientific Notation Concept 00:06:32<br>Binary Number Representation Rules 00:07:28<br>Large Binary Number Example 00:08:24<br>Small Binary Number Example 00:09:31<br>Mixing Binary and Decimal Notation 00:12:54<br>Pure Binary Scientific Notation 00:13:04<br>Connection to IEEE 754 00:13:48<br>Conclusion and Call to Action 00:14:21<br>Engagement and Website Promotion 00:15:32</p>



<p class="wp-block-paragraph">Thanks for watching!</p>



<p class="wp-block-paragraph">Find us on other social media here:</p>



<ul class="wp-block-list">
<li>https://www.NeuralLantern.com/social</li>
</ul>



<p class="wp-block-paragraph">Please help support us!</p>



<ul class="wp-block-list">
<li>Subscribing + Sharing on Social Media</li>



<li>Leaving a comment or suggestion</li>



<li>Subscribing to our Blog</li>



<li>Watching the main &#8220;pinned&#8221; video of this channel for offers and extras</li>
</ul>



<p class="wp-block-paragraph">Hey there! Let&#8217;s talk about representing binary numbers with fractions in scientific notation.</p>



<p class="wp-block-paragraph">Why would you need to do this? Probably the best use that I can think of off the top of my head</p>



<p class="wp-block-paragraph">is being able to represent binary numbers with fractions inside your machine in a format known</p>



<p class="wp-block-paragraph">It&#8217;s just a crucial step before you can represent numbers inside your machine using IEEE 754.</p>



<p class="wp-block-paragraph">Okay, so first off, let me just show you a little bit here about scientific notation.</p>



<p class="wp-block-paragraph">So you probably have seen something like this before where it&#8217;s like 8.3873,</p>



<p class="wp-block-paragraph">and then you&#8217;ll see like a multiplier times 10 to the fifth power, right?</p>



<p class="wp-block-paragraph">I can&#8217;t really type this out very well, so maybe I could just draw it for a second, you know.</p>



<p class="wp-block-paragraph">well so maybe I could just draw it for a second you know 8.54 times 10 to the fifth power right</p>



<p class="wp-block-paragraph">that&#8217;s what I&#8217;m trying to convey but anyway so about scientific notation itself it&#8217;s standardized</p>



<p class="wp-block-paragraph">so that it&#8217;s easier to use and that is you know it&#8217;s just like faster for everyone to understand</p>



<p class="wp-block-paragraph">and there&#8217;s less confusion part of the standard is that you always want to have a number on the</p>



<p class="wp-block-paragraph">that is between 1 and 9 inclusive. You don&#8217;t ever actually want to have a 0 there that would be bad.</p>



<p class="wp-block-paragraph">You don&#8217;t want to have a 10 or anything greater that would also be bad. You just want to have</p>



<p class="wp-block-paragraph">1, 2, 3, 4, 5, 6, 7, 8, 9 on the left side. And then on the fractional side,</p>



<p class="wp-block-paragraph">you want to have a number that just kind of like helps you represent the entire</p>



<p class="wp-block-paragraph">original number without losing precision. And then on the right side, you want a number,</p>



<p class="wp-block-paragraph">a number, let&#8217;s say like x to the y power, where x is the base of the number system you&#8217;re working</p>



<p class="wp-block-paragraph">in. So this is decimal. The base for decimal is 10. So we&#8217;re going to say 10 to the something</p>



<p class="wp-block-paragraph">power. What is the power? The power here helps you understand how big or small the number on</p>



<p class="wp-block-paragraph">the left really is. That&#8217;s kind of one of the benefits of scientific notation. It seems to</p>



<p class="wp-block-paragraph">help you understand a little bit more of how big or how small a number is rather than exactly</p>



<p class="wp-block-paragraph">than exactly down to you know the last digit what what is the number precisely so we could say for</p>



<p class="wp-block-paragraph">now it focuses more on largeness or smallness than preciseness what number are we actually</p>



<p class="wp-block-paragraph">representing with this in scientific notation well times 10 to the fifth power just means move the</p>



<p class="wp-block-paragraph">decimal point over a certain number of times so uh you know that&#8217;s why we have 10 to the something</p>



<p class="wp-block-paragraph">go left or right in a base 10 number you&#8217;re looking at a different number that has a factor</p>



<p class="wp-block-paragraph">of 10 for its strength in either direction like multiply by 10 multiply by 10 multiply by 10</p>



<p class="wp-block-paragraph">or divide by 10 divide by 10 divide by 10 in the other direction so this means we want to move the</p>



<p class="wp-block-paragraph">decimal point five times to the right to increase the strength of the number times five so one two</p>



<p class="wp-block-paragraph">three four five if we put the decimal number there then this is the number we were going to represent</p>



<p class="wp-block-paragraph">number we were going to represent originally so if somebody says hey give me this number 838730</p>



<p class="wp-block-paragraph">and put it in scientific notation then you your first instinct is to say all right let&#8217;s uh type</p>



<p class="wp-block-paragraph">that number out and we&#8217;ll put like a dot zero there and it will just we&#8217;ll move the decimal</p>



<p class="wp-block-paragraph">point over until there&#8217;s only one digit um and it&#8217;s a you know somewhere between a one and a nine</p>



<p class="wp-block-paragraph">three four five times over in order to get the decimal point there so that</p>



<p class="wp-block-paragraph">means it&#8217;s going to be this times 10 to the fifth power because we moved it over</p>



<p class="wp-block-paragraph">five times and you can see that&#8217;s the original number that I showed you these</p>



<p class="wp-block-paragraph">zeros at the very end they don&#8217;t actually mean anything so we can omit</p>



<p class="wp-block-paragraph">them probably a smarter idea to omit them and that&#8217;s why we see numbers that</p>



<p class="wp-block-paragraph">way okay so keep that in mind there&#8217;s only one digit let&#8217;s maybe do like</p>



<p class="wp-block-paragraph">practice number here I have a couple practice numbers written down already</p>



<p class="wp-block-paragraph">let&#8217;s see so we&#8217;ll start with this number a huge gigantic number just to</p>



<p class="wp-block-paragraph">practice if we copy paste this down to the next line and then we decide all</p>



<p class="wp-block-paragraph">right how many times do we need to move the decimal point to get the decimal</p>



<p class="wp-block-paragraph">point right there so that the two is the first number remember one to nine</p>



<p class="wp-block-paragraph">inclusive so I&#8217;ll just I&#8217;ll use two decimal points so I can count more</p>



<p class="wp-block-paragraph">9, 10, 11, 12, 13.</p>



<p class="wp-block-paragraph">So that means I did 13 moves.</p>



<p class="wp-block-paragraph">I&#8217;ll put 13 right here so I don&#8217;t forget.</p>



<p class="wp-block-paragraph">Times 10 to the 13th power.</p>



<p class="wp-block-paragraph">And the 13 is positive because when we&#8217;re looking at the scientifically notated format</p>



<p class="wp-block-paragraph">of the same number, you know, 2 point something is way smaller than the original number.</p>



<p class="wp-block-paragraph">So we want the scientifically notated format or form to get bigger in order to reach this</p>



<p class="wp-block-paragraph">number.</p>



<p class="wp-block-paragraph">in order to reach this number so that means 10 times sorry times 10 to a positive number positive</p>



<p class="wp-block-paragraph">means it&#8217;ll be bigger in its original form okay so now let&#8217;s do another practice number</p>



<p class="wp-block-paragraph">let&#8217;s do a number that&#8217;s really really really small like you&#8217;re inside of inner space or</p>



<p class="wp-block-paragraph">something so we start up with this number and we still want to have a number between</p>



<p class="wp-block-paragraph">rewrite it here I really want to have eight point something because that&#8217;s the first number that&#8217;s</p>



<p class="wp-block-paragraph">bigger than zero that I can see so again I&#8217;m using two decimal points so that it&#8217;s easy for me to</p>



<p class="wp-block-paragraph">count I&#8217;m going to go one two three four five six seven I had to move it seven times so it&#8217;s going</p>



<p class="wp-block-paragraph">to be negative seven is going to be the exponent so you know raised something raised to the negative</p>



<p class="wp-block-paragraph">seven it&#8217;s still going to be 10 to the negative seven that I multiply it by so then I&#8217;ll say get</p>



<p class="wp-block-paragraph">And now this is the same number represented in scientific notation.</p>



<p class="wp-block-paragraph">It should have all the same digits.</p>



<p class="wp-block-paragraph">The decimal point basically should just be moved.</p>



<p class="wp-block-paragraph">Of course, you know, when you represent in scientific notation,</p>



<p class="wp-block-paragraph">depending on what standard you&#8217;re working with,</p>



<p class="wp-block-paragraph">you might actually omit some of the numbers at the very end of the fraction here.</p>



<p class="wp-block-paragraph">But that&#8217;s why we say this is kind of more to impress upon you the smallness or largeness of a number</p>



<p class="wp-block-paragraph">rather than represent the number exactly precisely.</p>



<p class="wp-block-paragraph">okay so we got that two practices in there how can we do this same exact concept in binary</p>



<p class="wp-block-paragraph">well keep in mind in binary binary is a base two number this video is not about binary conversion</p>



<p class="wp-block-paragraph">as a whole number or binary with fraction let&#8217;s just pretend that we already know how to do that</p>



<p class="wp-block-paragraph">and we have a binary number to start off with so let me grab my example number here</p>



<p class="wp-block-paragraph">have some kind of a binary number with a fraction, which you can do if you don&#8217;t understand how to do</p>



<p class="wp-block-paragraph">this part yet from decimal with a fraction to binary with a fraction or back and forth.</p>



<p class="wp-block-paragraph">See my other videos. For now, we&#8217;ll assume you can do this. So how can we get this in scientific</p>



<p class="wp-block-paragraph">notation? So the first thing we have to understand is that it&#8217;s going to be, you know, some number</p>



<p class="wp-block-paragraph">right because that was the format we used before the number should only start with a one it should</p>



<p class="wp-block-paragraph">never even start with a zero remember in binary we can only use ones and zeros before i said here</p>



<p class="wp-block-paragraph">let me just show you this real fast again before i said the starting number has to be one through</p>



<p class="wp-block-paragraph">nine inclusive that was because in decimal we have zero one two three four five six seven eight nine</p>



<p class="wp-block-paragraph">be only use you know one two three five six seven eight nine so but in binary um i&#8217;ll put like</p>



<p class="wp-block-paragraph">a character set like the available characters we can use to represent the numbers in decimal</p>



<p class="wp-block-paragraph">so in binary the care set that we can use is just you know a zero and a one only but the same rule</p>



<p class="wp-block-paragraph">the one so that means the first number always has to be one it has to be always one dot something</p>



<p class="wp-block-paragraph">for our purposes to represent the same number in scientific notation so it&#8217;s going to be</p>



<p class="wp-block-paragraph">this and obviously that one has to be it it cannot ever be a zero so i&#8217;m going to put the</p>



<p class="wp-block-paragraph">decimal point there uh and then i&#8217;m just going to count like how much did i actually move the</p>



<p class="wp-block-paragraph">seven eight nine ten eleven twelve thirteen fourteen fifteen six just fifteen just fifteen not</p>



<p class="wp-block-paragraph">sixteen so i&#8217;m going to put times something to the fifteen power and remove that other decimal</p>



<p class="wp-block-paragraph">point and then the base is two so it&#8217;s going to be two to the fifteenth power</p>



<p class="wp-block-paragraph">so now maybe i should move that up a little bit</p>



<p class="wp-block-paragraph">gigantic number uh in scientific notation it&#8217;s going to look a little smaller but then the times</p>



<p class="wp-block-paragraph">base to the 15th power is going to help us understand how big it is oh it&#8217;s like pretty big</p>



<p class="wp-block-paragraph">let&#8217;s do the same thing backwards let&#8217;s say that we wanted to start off with a very very small</p>



<p class="wp-block-paragraph">number so it&#8217;s like you know a zero point something in binary so you can imagine if this is like one</p>



<p class="wp-block-paragraph">256 that&#8217;s probably going to be a number that&#8217;s no bigger than or just like slightly bigger than</p>



<p class="wp-block-paragraph">256 so it&#8217;s going to be like kind of a small number right well we&#8217;ll do the same thing just</p>



<p class="wp-block-paragraph">copy to another line and then make sure that the decimal point sits in a place where there&#8217;s always</p>



<p class="wp-block-paragraph">a one at the start</p>



<p class="wp-block-paragraph">and then just count the number of times you moved</p>



<p class="wp-block-paragraph">number of times you moved the number oh I guess before we would have possibly</p>



<p class="wp-block-paragraph">deleted numbers on the right if we were gonna reduce precision in this case</p>



<p class="wp-block-paragraph">after we count the numbers we&#8217;re gonna remove everything to the left of the one</p>



<p class="wp-block-paragraph">so that the one is in the first position and I&#8217;ll just go ahead and do it okay so</p>



<p class="wp-block-paragraph">how many times do we move it one two three four five six seven eight that&#8217;s</p>



<p class="wp-block-paragraph">eight times so I&#8217;m gonna put an eight there just to remind myself that there</p>



<p class="wp-block-paragraph">will be an eight I&#8217;ll remove all the stuff at the beginning that doesn&#8217;t</p>



<p class="wp-block-paragraph">all the stuff at the beginning that doesn&#8217;t matter anymore and it&#8217;s going to be times two because</p>



<p class="wp-block-paragraph">that&#8217;s our base to the eighth power but the original number is a lot smaller than the</p>



<p class="wp-block-paragraph">scientifically notated number looks so that means we have to put a negative eight because remember</p>



<p class="wp-block-paragraph">when you say times let me just show you this on a calculator when we say let&#8217;s let&#8217;s go back to</p>



<p class="wp-block-paragraph">fifth power then you know that we&#8217;re just basically adding four zeros right so</p>



<p class="wp-block-paragraph">like we have five total zeros so we&#8217;re adding four zeros to the ten but if we</p>



<p class="wp-block-paragraph">did to the negative five power we&#8217;re gonna be like dividing it by ten a bunch</p>



<p class="wp-block-paragraph">of times so instead of multiplying it by ten for a total of five times we&#8217;re</p>



<p class="wp-block-paragraph">gonna divide by ten so then the number gets really really really small so that</p>



<p class="wp-block-paragraph">means when we say two to the negative eight power we&#8217;re gonna be dividing it</p>



<p class="wp-block-paragraph">We&#8217;re going to be dividing it by two that many times.</p>



<p class="wp-block-paragraph">And so we end up with a really, really, really small number.</p>



<p class="wp-block-paragraph">Isn&#8217;t that what I kind of said?</p>



<p class="wp-block-paragraph">Let&#8217;s see.</p>



<p class="wp-block-paragraph">I mean, like, not exactly, but, you know, it&#8217;s like 0.003 and then some numbers after that.</p>



<p class="wp-block-paragraph">Didn&#8217;t I say one divided by 256?</p>



<p class="wp-block-paragraph">It&#8217;s 0.003 and then some numbers.</p>



<p class="wp-block-paragraph">So this number is just a little bit bigger than 0.003.</p>



<p class="wp-block-paragraph">Nine.</p>



<p class="wp-block-paragraph">Let&#8217;s see how much bigger it is.</p>



<p class="wp-block-paragraph">bigger it is point three six two five what</p>



<p class="wp-block-paragraph">oh because i&#8217;m not i&#8217;m not including the the part on the left that we will multiply it by so if i</p>



<p class="wp-block-paragraph">you know if i did some like binary up here and i was in binary mode then it would probably make</p>



<p class="wp-block-paragraph">more sense it ended up being exactly the same exact number that&#8217;s why i was confused because</p>



<p class="wp-block-paragraph">if we just type that part on the right side then it really is going to be one over 256.</p>



<p class="wp-block-paragraph">Anyway, long story short, we have this number here, the fractional part, and then we&#8217;re</p>



<p class="wp-block-paragraph">going to multiply it by two to the something power.</p>



<p class="wp-block-paragraph">Notice something in particular that I&#8217;m doing, which is probably my mistake, but I kind of</p>



<p class="wp-block-paragraph">like doing it this way.</p>



<p class="wp-block-paragraph">Notice how the left part is in binary and the right part is in decimal.</p>



<p class="wp-block-paragraph">There&#8217;s no number two in binary or no number eight in binary.</p>



<p class="wp-block-paragraph">numbers like this to scientific notation so that you can convert a binary number to i triple e</p>



<p class="wp-block-paragraph">floating point number this is as far as you really need to go but if you truly want to represent a</p>



<p class="wp-block-paragraph">binary number in scientific notation then you should also convert all of the relevant parts</p>



<p class="wp-block-paragraph">so how do we represent uh the number two in binary it&#8217;s going to be one zero how do we represent the</p>



<p class="wp-block-paragraph">number eight in binary it&#8217;s going to be one two four eight it&#8217;s going to be that so uh you know</p>



<p class="wp-block-paragraph">big number times 10 in binary is still the number two to the something power the negative 1000 in</p>



<p class="wp-block-paragraph">binary power is going to be you know eight the negative eight power so this is great if you just</p>



<p class="wp-block-paragraph">want to write an entire number in scientific notation but uh you know in probably my next</p>



<p class="wp-block-paragraph">video when we talk about ieee 754 notation this is as far as you really need to go</p>



<p class="wp-block-paragraph">eight number into a a whole number in binary and then putting that somewhere but so just</p>



<p class="wp-block-paragraph">forget about this for now keep in mind this is how far you have to go if you want to go to ieee</p>



<p class="wp-block-paragraph">if you only want to be in pure binary then this is what it would look like</p>



<p class="wp-block-paragraph">okay that&#8217;s it uh i think that&#8217;s all the example i have for you today in this video thank you so</p>



<p class="wp-block-paragraph">much for watching i hope you learned a little bit and had a little bit of fun see you in the next</p>



<p class="wp-block-paragraph">video</p>



<p class="wp-block-paragraph">Hey everybody!</p>



<p class="wp-block-paragraph">Thanks for watching this video again from the bottom of my heart.</p>



<p class="wp-block-paragraph">I really appreciate it.</p>



<p class="wp-block-paragraph">I do hope you did learn something and have some fun.</p>



<p class="wp-block-paragraph">If you could do me a please, a small little favor, could you please subscribe and follow</p>



<p class="wp-block-paragraph">this channel or these videos or whatever it is you do on the current social media website</p>



<p class="wp-block-paragraph">that you&#8217;re looking at right now.</p>



<p class="wp-block-paragraph">It would really mean the world to me and it&#8217;ll help make more videos and grow this community.</p>



<p class="wp-block-paragraph">better videos or just I&#8217;ll be able to keep making videos in general so please</p>



<p class="wp-block-paragraph">do do me a kindness and and subscribe you know sometimes I&#8217;m sleeping in the</p>



<p class="wp-block-paragraph">middle of the night and I just wake up because I know somebody subscribed or</p>



<p class="wp-block-paragraph">followed it just wakes me up and I get filled with joy that&#8217;s exactly what</p>



<p class="wp-block-paragraph">happens every single time so you could do it as a nice favor to me or you could</p>



<p class="wp-block-paragraph">you control me if you want to just wake me up in the middle of the night just</p>



<p class="wp-block-paragraph">subscribe and then I&#8217;ll just wake up I promise that&#8217;s what will happen also if</p>



<p class="wp-block-paragraph">If you look at the middle of the screen right now, you should see a QR code, which you can scan in order to go to the website, which I think is also named somewhere at the bottom of this video.</p>



<p class="wp-block-paragraph">And it&#8217;ll take you to my main website where you can just kind of like see all the videos I published and the services and tutorials and things that I offer and all that good stuff.</p>



<p class="wp-block-paragraph">And if you have a suggestion for clarifications or errata or just future videos that you want to see, please leave a comment.</p>



<p class="wp-block-paragraph">or if you just want to say hey what&#8217;s up what&#8217;s going on you know just send me a comment whatever</p>



<p class="wp-block-paragraph">i also wake up for those in the middle of the night i get i wake up in a cold sweat and i&#8217;m like</p>



<p class="wp-block-paragraph">it would really it really mean the world to me i would really appreciate it so again thank you</p>



<p class="wp-block-paragraph">so much for watching this video and um enjoy the cool music as as i fade into the darkness</p>



<p class="wp-block-paragraph">Thank you.</p>
<p>The post <a href="https://www.NeuralLantern.com/how-to-master-binary-scientific-notation-with-fun-examples/">How to Master Binary Scientific Notation (with Fun Examples!)</a> appeared first on <a href="https://www.NeuralLantern.com">NeuralLantern.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.NeuralLantern.com/how-to-master-binary-scientific-notation-with-fun-examples/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
