<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Jefferson Oliveira</title>
    <description>The latest articles on DEV Community by Jefferson Oliveira (@jeffersonmourak).</description>
    <link>https://dev.to/jeffersonmourak</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F58993%2Ff88926dc-ecf2-46d3-9567-d1d6d2622dae.png</url>
      <title>DEV Community: Jefferson Oliveira</title>
      <link>https://dev.to/jeffersonmourak</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jeffersonmourak"/>
    <language>en</language>
    <item>
      <title>Introducing circ, a small language for digital circuits</title>
      <dc:creator>Jefferson Oliveira</dc:creator>
      <pubDate>Wed, 13 May 2026 12:01:10 +0000</pubDate>
      <link>https://dev.to/jeffersonmourak/introducing-circ-a-small-language-for-digital-circuits-22pc</link>
      <guid>https://dev.to/jeffersonmourak/introducing-circ-a-small-language-for-digital-circuits-22pc</guid>
      <description>&lt;p&gt;Hey Y'all,&lt;/p&gt;

&lt;p&gt;I've been writing a blog series on the fundamentals of computing, logic gates, binary, memory, that sort of thing, and every post had circuit diagrams in it. For a long time these were static SVGs I drew by hand, then a TypeScript renderer I kept hacking on, but neither could simulate anything. The drawings were just drawings.&lt;/p&gt;

&lt;p&gt;Trying to fix this problem, I wrote a language called &lt;code&gt;circ&lt;/code&gt; that lets you describe digital circuits and compiles them to WebAssembly modules that run in the browser. Right now it lives scattered across the series, every interactive circuit you see in those posts is a &lt;code&gt;.circ&lt;/code&gt; file.&lt;/p&gt;

&lt;p&gt;It's a small language. There are only six primitives (&lt;code&gt;input&lt;/code&gt;, &lt;code&gt;output&lt;/code&gt;, &lt;code&gt;and&lt;/code&gt;, &lt;code&gt;not&lt;/code&gt;, &lt;code&gt;wire&lt;/code&gt;, &lt;code&gt;led&lt;/code&gt;), and the familiar gates you'd expect to be built in (&lt;code&gt;or&lt;/code&gt;, &lt;code&gt;nand&lt;/code&gt;, &lt;code&gt;xor&lt;/code&gt;, &lt;code&gt;nor&lt;/code&gt;, &lt;code&gt;xnor&lt;/code&gt;) are themselves written in &lt;code&gt;.circ&lt;/code&gt; and live inside the compiler as embedded files. The standard library is just more of the language, which makes me very happy.&lt;/p&gt;

&lt;p&gt;The compiler is written in Zig and uses &lt;a href="https://clarete.li/langlang/" rel="noopener noreferrer"&gt;langlang&lt;/a&gt; for the PEG parser. At build time the simulation runtime is compiled to &lt;code&gt;wasm32-freestanding&lt;/code&gt; and embedded into the CLI, and when you compile a circuit the resolved topology gets serialized into a custom WASM section and spliced onto that prebuilt blob. Each compiled circuit ends up as a single self-contained &lt;code&gt;.wasm&lt;/code&gt; file, no toolchain required to run it. From the same &lt;code&gt;.circ&lt;/code&gt; file you can also get an ASCII schematic via &lt;code&gt;--preview&lt;/code&gt; and a truth table via &lt;code&gt;--truth-table&lt;/code&gt; in Markdown, CSV, or JSON.&lt;/p&gt;

&lt;p&gt;I just published a letter introducing the language: &lt;a href="https://jeffersonmourak.com/blog/circ-en/" rel="noopener noreferrer"&gt;link to blog&lt;/a&gt;. The language has a site with the full reference at &lt;a href="https://circ-lang.org/" rel="noopener noreferrer"&gt;circ-lang.org&lt;/a&gt;, and the source is on GitHub: &lt;a href="https://github.com/jeffersonmourak/circ-compiler" rel="noopener noreferrer"&gt;link to repo&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I'd love any feedback you have, especially on the surface syntax. I've been the only user for a while now, and I'm sure there are sharp edges I've stopped being able to see.&lt;/p&gt;

&lt;p&gt;Thanks for reading 😊&lt;/p&gt;

</description>
      <category>webassembly</category>
      <category>zig</category>
      <category>compilers</category>
      <category>programming</category>
    </item>
    <item>
      <title>Pleasure to meet you, circ!</title>
      <dc:creator>Jefferson Oliveira</dc:creator>
      <pubDate>Tue, 12 May 2026 10:28:04 +0000</pubDate>
      <link>https://dev.to/jeffersonmourak/pleasure-to-meet-you-circ-52nd</link>
      <guid>https://dev.to/jeffersonmourak/pleasure-to-meet-you-circ-52nd</guid>
      <description>&lt;p&gt;Hey y’all! If you’ve been following the fundamentals of computing series here, you’ve noticed those little widgets. You can click them, toggle the switches, watch the LEDs light up, peek at the circuit topology. Today I want to tell you what’s actually running in them, because I made it.&lt;/p&gt;

&lt;p&gt;It’s called &lt;code&gt;circ&lt;/code&gt;. It’s a small language for describing digital circuits, and a compiler that turns the description into something your browser can run. First of all I want you to understand this isn’t a serious systems language (&lt;em&gt;yet&lt;/em&gt;), and I believe it’s great for this blog but not ready for production. For now it exists for the sole purpose of having the circuits here &lt;em&gt;actually work&lt;/em&gt;, instead of being static drawings or handcrafted simulators.&lt;/p&gt;

&lt;h2&gt;
  
  
  How it reads
&lt;/h2&gt;

&lt;p&gt;I think the best way to introduce a language is to let you look at it. Here’s a half-adder written in &lt;code&gt;.circ&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight verilog"&gt;&lt;code&gt;&lt;span class="kt"&gt;input&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;

&lt;span class="kt"&gt;xor&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="kt"&gt;and&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="kt"&gt;output&lt;/span&gt; &lt;span class="n"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;in&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;out&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="kt"&gt;output&lt;/span&gt; &lt;span class="n"&gt;carry&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;in&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;out&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That’s the whole file. You declare your inputs, you instantiate gates and give them names, you wire each gate’s ports to the signals that drive them, and you declare which signals leave through the outputs. Doesn’t it read a little like a recipe? &lt;em&gt;Take two inputs. Combine &lt;code&gt;a&lt;/code&gt; and &lt;code&gt;b&lt;/code&gt; with an XOR, call it &lt;code&gt;s&lt;/code&gt;. Combine the same two with an AND, call it &lt;code&gt;c&lt;/code&gt;. Send &lt;code&gt;s.out&lt;/code&gt; to the &lt;code&gt;sum&lt;/code&gt; output, &lt;code&gt;c.out&lt;/code&gt; to the &lt;code&gt;carry&lt;/code&gt;.&lt;/em&gt; That’s it.&lt;/p&gt;

&lt;p&gt;The primitives are deliberately tiny: &lt;code&gt;input&lt;/code&gt;, &lt;code&gt;output&lt;/code&gt;, &lt;code&gt;and&lt;/code&gt;, &lt;code&gt;not&lt;/code&gt;, &lt;code&gt;wire&lt;/code&gt;, &lt;code&gt;led&lt;/code&gt;. Six things. Everything else is built from those.&lt;/p&gt;

&lt;p&gt;And here’s a detail I’m a little smug about: the built-in gates &lt;code&gt;or&lt;/code&gt;, &lt;code&gt;nand&lt;/code&gt;, &lt;code&gt;nor&lt;/code&gt;, &lt;code&gt;xor&lt;/code&gt;, &lt;code&gt;xnor&lt;/code&gt; are themselves written in &lt;code&gt;.circ&lt;/code&gt;. The compiler’s entire “standard library” is five tiny files that look exactly like the one above. When you write &lt;code&gt;xor s(a=a, b=b)&lt;/code&gt;, the compiler quietly pulls in a five-line file that defines XOR in terms of AND, OR, and NAND. The language is small enough to be its own standard library, and that makes me unreasonably happy.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where it came from
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;circ&lt;/code&gt; didn’t start as a language. It started as me wanting to draw circuits.&lt;/p&gt;

&lt;p&gt;I’d been writing this series for a while, and every circuit in every post was a static SVG I’d hand-drawn or coaxed out of a TypeScript renderer I kept patching. The drawings worked, but they were &lt;em&gt;just drawings&lt;/em&gt;. You couldn’t toggle a switch and watch the LED change. You couldn’t ask “what does this circuit &lt;em&gt;do&lt;/em&gt;, exactly?” and get an answer. They were illustrations of computers, not computers.&lt;/p&gt;

&lt;p&gt;Around the same time I bought &lt;a href="https://www.amazon.com/Elements-Computing-Systems-Building-Principles/dp/0262640686/ref=ed_oe_p" rel="noopener noreferrer"&gt;&lt;em&gt;The Elements of Computing Systems&lt;/em&gt;&lt;/a&gt;, and this book hexed me (pun intended) with the curse of curiosity, which led me right into &lt;a href="https://www.nand2tetris.org/" rel="noopener noreferrer"&gt;&lt;em&gt;Nand to Tetris&lt;/em&gt;&lt;/a&gt;. In it, you build everything from a single NAND gate, in a tiny language called HDL, and every component you write actually runs. The combination of “describe a circuit in a few lines” and “now press play and watch it work” is how circuits should feel when you’re learning about them. So I wanted that, for this blog, for you. The widgets in the posts you’ve already read are the result.&lt;/p&gt;

&lt;p&gt;The name is the most boring part of the story: &lt;code&gt;circ&lt;/code&gt; is short for circuit (&lt;em&gt;I am not a poet, sorry.&lt;/em&gt;)&lt;/p&gt;

&lt;h2&gt;
  
  
  The two things I love most
&lt;/h2&gt;

&lt;p&gt;Once the compiler started working, two things fell out of it that I didn’t expect to love as much as I do.&lt;/p&gt;

&lt;p&gt;The first is that &lt;code&gt;circ&lt;/code&gt; can draw itself. Hand it a circuit and it’ll produce an ASCII schematic, complete with rounded corners, fan-out dots, and wires that detour politely around gates that sit in their way. Here’s the half-adder from earlier, rendered by the compiler itself:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;╭───╮ ╭───╮ ╭───────╮
│ a ├○─●─▶┤ │ ╭──────▶┤ carry │
╰───╯ │ │AND├○╯ ╰───────╯
      ╭┼─▶┤ │
      ││ ╰───╯
      ││
╭───╮ ││ ╭───────╮ ╭─────╮
│ b ├○●╰─▶┤ │ ╭──▶┤ sum │
╰───╯ │ │[xor:s]├○╯ ╰─────╯
      ╰──▶┤ │
          ╰───────╯

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The second is that &lt;code&gt;circ&lt;/code&gt; can tabulate itself. Hand it the same file and ask for &lt;code&gt;--truth-table&lt;/code&gt;, and you get:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;a&lt;/th&gt;
&lt;th&gt;b&lt;/th&gt;
&lt;th&gt;sum&lt;/th&gt;
&lt;th&gt;cout&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;That’s the beauty of it: using only 5 lines you have a circuit description, a picture of itself, and proof that it does what it claims. Every interactive widget in every post of this series has been &lt;code&gt;circ&lt;/code&gt; doing this quietly in the background, three times over. Once to render the schematic you see, once to run the simulation when you toggle a switch, once to prove the gates behave the way I said they would.&lt;/p&gt;

&lt;h2&gt;
  
  
  Until we meet again
&lt;/h2&gt;

&lt;p&gt;That’s just the surface of it. There’s a parser, a resolver, a validator with stable error codes, a tiny WebAssembly runtime that the compiler embeds inside every artifact so the whole thing runs in your browser without needing any toolchain on your machine. But those are stories for other days.&lt;/p&gt;

&lt;p&gt;If you want to dig deeper, the language has a home of its own at &lt;a href="https://circ-lang.org/" rel="noopener noreferrer"&gt;circ-lang.org&lt;/a&gt;, with the full reference and more examples than I could fit here.&lt;/p&gt;

&lt;p&gt;For now, the next time you click on a widget in one of these posts, you’ll know what you’re looking at. It’s &lt;code&gt;circ&lt;/code&gt;. Pleasure to meet you.&lt;/p&gt;

&lt;h3&gt;
  
  
  Special thanks
&lt;/h3&gt;

&lt;p&gt;Before we say goodbye, I want to give a special shoutout to &lt;a href="https://clarete.li/" rel="noopener noreferrer"&gt;@clarete&lt;/a&gt;. He is the brain behind &lt;a href="https://clarete.li/langlang/" rel="noopener noreferrer"&gt;langlang&lt;/a&gt;, the parser generator that powers this language. He has been hammering my ears about langlang for years and I couldn’t be more proud of what he has done.&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/jeffersonmourak/circ-compiler" rel="noopener noreferrer"&gt;&lt;code&gt;circ-compiler&lt;/code&gt; on GitHub&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://circ-lang.org/" rel="noopener noreferrer"&gt;circ-lang.org&lt;/a&gt;, the language reference and examples&lt;/li&gt;
&lt;li&gt;&lt;a href="https://ziglang.org/" rel="noopener noreferrer"&gt;Zig&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://clarete.li/langlang/" rel="noopener noreferrer"&gt;langlang&lt;/a&gt;, the PEG parser generator that builds the &lt;code&gt;.circ&lt;/code&gt; grammar&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.nand2tetris.org/" rel="noopener noreferrer"&gt;From Nand to Tetris&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>compilers</category>
      <category>languages</category>
      <category>webassembly</category>
      <category>dsl</category>
    </item>
    <item>
      <title>Prazer, circ!</title>
      <dc:creator>Jefferson Oliveira</dc:creator>
      <pubDate>Tue, 12 May 2026 10:27:04 +0000</pubDate>
      <link>https://dev.to/jeffersonmourak/prazer-circ-41gc</link>
      <guid>https://dev.to/jeffersonmourak/prazer-circ-41gc</guid>
      <description>&lt;p&gt;Olá pessoal, tudo bom? Se vocês têm acompanhado a série de fundamentos da computação aqui, com certeza notaram aqueles circuitinhos. Dá pra clicar neles, mexer nos interruptores, ver os LEDs acendendo, espiar a topologia do circuito. Hoje eu quero contar o que de verdade está rodando neles, porque fui eu que fiz.&lt;/p&gt;

&lt;p&gt;Ele se chama &lt;code&gt;circ&lt;/code&gt;. É uma linguagem pra descrever circuitos digitais, e um compilador que transforma essa descrição em algo que o seu navegador consegue rodar. Antes de mais nada, quero deixar claro: isso não é uma linguagem séria de sistemas (&lt;em&gt;ainda&lt;/em&gt;), e eu acredito que é ótima pra esse blog mas não está pronta pra produção. Por enquanto ela existe pelo único motivo de fazer os circuitos daqui &lt;em&gt;funcionarem de verdade&lt;/em&gt;, em vez de serem desenhos estáticos ou simuladores feitos na mão.&lt;/p&gt;

&lt;h2&gt;
  
  
  Aprendendo a ler
&lt;/h2&gt;

&lt;p&gt;Eu acho que a melhor forma de apresentar uma linguagem é deixar você olhar pra ela. Aqui está um meio-somador (&lt;em&gt;half-adder&lt;/em&gt;) escrito em &lt;code&gt;.circ&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight verilog"&gt;&lt;code&gt;&lt;span class="kt"&gt;input&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;

&lt;span class="kt"&gt;xor&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="kt"&gt;and&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="kt"&gt;output&lt;/span&gt; &lt;span class="n"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;in&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;out&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="kt"&gt;output&lt;/span&gt; &lt;span class="n"&gt;carry&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;in&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;out&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;É o arquivo inteiro. Você declara as suas entradas, instancia as portas e dá um nome pra elas, conecta as portas de cada uma aos sinais que as alimentam, e declara quais sinais saem pelas saídas. Não parece um pouco com uma receita? &lt;em&gt;Pegue duas entradas. Combine &lt;code&gt;a&lt;/code&gt; e &lt;code&gt;b&lt;/code&gt; com um XOR, chame de &lt;code&gt;s&lt;/code&gt;. Combine as mesmas duas com um AND, chame de &lt;code&gt;c&lt;/code&gt;. Mande &lt;code&gt;s.out&lt;/code&gt; pra saída &lt;code&gt;sum&lt;/code&gt;, e &lt;code&gt;c.out&lt;/code&gt; pra &lt;code&gt;carry&lt;/code&gt;.&lt;/em&gt; É isso.&lt;/p&gt;

&lt;p&gt;As primitivas são propositalmente minúsculas: &lt;code&gt;input&lt;/code&gt;, &lt;code&gt;output&lt;/code&gt;, &lt;code&gt;and&lt;/code&gt;, &lt;code&gt;not&lt;/code&gt;, &lt;code&gt;wire&lt;/code&gt;, &lt;code&gt;led&lt;/code&gt;. Seis coisas. Todo o resto é construído a partir delas.&lt;/p&gt;

&lt;p&gt;E aqui vai um detalhe do qual eu me orgulho um pouco: as portas &lt;code&gt;or&lt;/code&gt;, &lt;code&gt;nand&lt;/code&gt;, &lt;code&gt;nor&lt;/code&gt;, &lt;code&gt;xor&lt;/code&gt;, &lt;code&gt;xnor&lt;/code&gt; também são escritas em &lt;code&gt;.circ&lt;/code&gt;. A “biblioteca padrão” inteira do compilador são cinco arquivos que se parecem exatamente com o de cima. Quando você escreve &lt;code&gt;xor s(a=a, b=b)&lt;/code&gt;, o compilador silenciosamente puxa um arquivo de cinco linhas que define XOR em termos de AND, OR e NAND. A linguagem é pequena o suficiente pra ser a sua própria biblioteca padrão, e isso pra mim é fascinante.&lt;/p&gt;

&lt;h2&gt;
  
  
  Senta que lá vem história
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;circ&lt;/code&gt; não começou como uma linguagem. Começou como eu querendo desenhar circuitos.&lt;/p&gt;

&lt;p&gt;Eu vinha escrevendo essa série há um tempo, e todo circuito de todo post era um SVG estático que eu tinha desenhado na mão ou arrancado de um renderizador em TypeScript que eu não parava de remendar. Os desenhos funcionavam, mas eram &lt;em&gt;só desenhos&lt;/em&gt;. Você não podia mexer numa chave e ver o LED mudar. Você não podia perguntar “o que esse circuito &lt;em&gt;faz&lt;/em&gt;, exatamente?” e receber uma resposta. Eram ilustrações de computadores, não computadores.&lt;/p&gt;

&lt;p&gt;Mais ou menos na mesma época eu comprei o &lt;a href="https://www.amazon.com/Elements-Computing-Systems-Building-Principles/dp/0262640686/ref=ed_oe_p" rel="noopener noreferrer"&gt;&lt;em&gt;The Elements of Computing Systems&lt;/em&gt;&lt;/a&gt;, e esse livro explodiu minha cabeça e me levou direto pro &lt;a href="https://www.nand2tetris.org/" rel="noopener noreferrer"&gt;&lt;em&gt;Nand to Tetris&lt;/em&gt;&lt;/a&gt;. Nele, você constrói tudo a partir de uma única porta NAND, numa linguagenzinha chamada HDL, e cada componente que você escreve realmente roda. A combinação de “descreva um circuito em poucas linhas” e “agora aperte play e veja funcionar” é como deveria ser quando você está aprendendo sobre circuitos. Então eu quis isso, pra esse blog, pra você. Os widgets dos posts que você já leu são o resultado.&lt;/p&gt;

&lt;p&gt;O nome é a parte mais sem graça da história: &lt;code&gt;circ&lt;/code&gt; é abreviação de &lt;em&gt;circuit&lt;/em&gt; (&lt;em&gt;não sou poeta, desculpa.&lt;/em&gt;)&lt;/p&gt;

&lt;h2&gt;
  
  
  As cerejas do bolo
&lt;/h2&gt;

&lt;p&gt;Assim que o compilador começou a funcionar, duas coisas saíram dele que eu não esperava amar tanto quanto amo.&lt;/p&gt;

&lt;p&gt;A primeira é que o &lt;code&gt;circ&lt;/code&gt; consegue se desenhar. Entrega um circuito pra ele e ele produz um esquema em ASCII, completo com cantos arredondados, pontos de fan-out, e fios que desviam educadamente das portas que estão no caminho. Aqui está o meio-somador de antes, renderizado pelo próprio compilador:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;╭───╮ ╭───╮ ╭───────╮
│ a ├○─●─▶┤ │ ╭──────▶┤ carry │
╰───╯ │ │AND├○╯ ╰───────╯
      ╭┼─▶┤ │
      ││ ╰───╯
      ││
╭───╮ ││ ╭───────╮ ╭─────╮
│ b ├○●╰─▶┤ │ ╭──▶┤ sum │
╰───╯ │ │[xor:s]├○╯ ╰─────╯
      ╰──▶┤ │
          ╰───────╯

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A segunda é que o &lt;code&gt;circ&lt;/code&gt; consegue se tabular. Entrega o mesmo arquivo pra ele e peça &lt;code&gt;--truth-table&lt;/code&gt;, e você recebe:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;a&lt;/th&gt;
&lt;th&gt;b&lt;/th&gt;
&lt;th&gt;sum&lt;/th&gt;
&lt;th&gt;cout&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Essa é a beleza da coisa: usando só 5 linhas você tem a descrição do circuito, uma imagem dele mesmo, e a prova de que ele faz o que diz que faz. Cada widget interativo de cada post dessa série tem sido o &lt;code&gt;circ&lt;/code&gt; fazendo isso silenciosamente no fundo, três vezes seguidas. Uma vez pra renderizar o esquema que você vê, uma vez pra rodar a simulação quando você mexe numa chave, e uma vez pra provar que as portas se comportam do jeito que eu disse que iam se comportar.&lt;/p&gt;

&lt;h2&gt;
  
  
  Até a próxima
&lt;/h2&gt;

&lt;p&gt;Isso é só a superfície. Tem um parser, um resolvedor, um validador com códigos de erro estáveis, um pequeno runtime em WebAssembly que o compilador injeta dentro de cada artefato pra que tudo rode no seu navegador sem precisar de toolchain nenhum na sua máquina. Mas essas são histórias pra outros dias.&lt;/p&gt;

&lt;p&gt;Se quiser se aprofundar, a linguagem tem um site só pra ela em &lt;a href="https://circ-lang.org/" rel="noopener noreferrer"&gt;circ-lang.org&lt;/a&gt;, com a referência completa e mais exemplos do que coube aqui.&lt;/p&gt;

&lt;p&gt;Por enquanto, da próxima vez que você clicar num widget em um desses posts, você vai saber o que está vendo. É o &lt;code&gt;circ&lt;/code&gt;. Prazer em te conhecer.&lt;/p&gt;

&lt;h3&gt;
  
  
  Agradecimentos especiais
&lt;/h3&gt;

&lt;p&gt;Antes de nos despedirmos, eu quero dar um agradecimento especial pro &lt;a href="https://clarete.li/" rel="noopener noreferrer"&gt;@clarete&lt;/a&gt;. Ele é o cérebro por trás do &lt;a href="https://clarete.li/langlang/" rel="noopener noreferrer"&gt;langlang&lt;/a&gt;, o gerador de parsers que dá vida pra essa linguagem. Ele vem martelando meus ouvidos sobre o langlang há anos, e eu não poderia estar mais orgulhoso do que ele construiu.&lt;/p&gt;

&lt;h2&gt;
  
  
  Referências
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/jeffersonmourak/circ-compiler" rel="noopener noreferrer"&gt;&lt;code&gt;circ-compiler&lt;/code&gt; no GitHub&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://circ-lang.org/" rel="noopener noreferrer"&gt;circ-lang.org&lt;/a&gt;, a referência da linguagem e exemplos&lt;/li&gt;
&lt;li&gt;&lt;a href="https://ziglang.org/" rel="noopener noreferrer"&gt;Zig&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://clarete.li/langlang/" rel="noopener noreferrer"&gt;langlang&lt;/a&gt;, o gerador de parser PEG que constrói a gramática do &lt;code&gt;.circ&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.nand2tetris.org/" rel="noopener noreferrer"&gt;From Nand to Tetris&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>compiladores</category>
      <category>linguagens</category>
      <category>webassembly</category>
      <category>dsl</category>
    </item>
    <item>
      <title>A Evolução da Escrita Digital - Do ASCII às Maravilhas do UTF-8</title>
      <dc:creator>Jefferson Oliveira</dc:creator>
      <pubDate>Thu, 07 Aug 2025 13:29:04 +0000</pubDate>
      <link>https://dev.to/jeffersonmourak/a-evolucao-da-escrita-digital-do-ascii-as-maravilhas-do-utf-8-1ao</link>
      <guid>https://dev.to/jeffersonmourak/a-evolucao-da-escrita-digital-do-ascii-as-maravilhas-do-utf-8-1ao</guid>
      <description>&lt;p&gt;Já imaginou como computadores transformam letras, números e emojis em zeros e uns que eles possam entender? Assim como nós, humanos, atribuímos significados às letras do alfabeto, o computador faz o mesmo. Vamos explorar aqui dois dos padrões mais populares de codificação de texto.&lt;/p&gt;

&lt;h3&gt;
  
  
  ASCII
&lt;/h3&gt;

&lt;p&gt;Desenvolvido na década de 1960, o ASCII (American Standard Code for Information Interchange) tem uma premissa bem simples: usando apenas 7 bits, consegue-se representar 127 números, deixando reservados os primeiros 32 números da sequência para comandos importantes de escrita. O restante é preenchido com letras, números e alguns caracteres de pontuação.&lt;/p&gt;

&lt;p&gt;As pessoas envolvidas no desenvolvimento do padrão fizeram de tal forma que a sequência do alfabeto pudesse ajudar na decodificação.&lt;/p&gt;

&lt;p&gt;Por exemplo, o caractere do número “0” é o número &lt;strong&gt;48&lt;/strong&gt; , que, representado em 7 bits, fica &lt;code&gt;011 0000&lt;/code&gt;. Assim como:&lt;/p&gt;

&lt;p&gt;1 → &lt;code&gt;011 0001&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;2 → &lt;code&gt;011 0010&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;3 → &lt;code&gt;011 0011&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Se notarem, os últimos 4 bits estão em sequência. Logo, para descobrir em ASCII qual o inteiro, é só subtrair 011 0000 (decimal: 48).&lt;/p&gt;

&lt;p&gt;Da mesma forma, as letras do alfabeto: “A” é &lt;strong&gt;65&lt;/strong&gt; → 100 0001 e o “a” é &lt;strong&gt;97&lt;/strong&gt; → 110 0001. Com isso, era possível codificar todas as letras do alfabeto inglês 🇬🇧.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Interactive Observable notebook widget — &lt;a href="https://jeffersonmourak.com/blog/unicode/" rel="noopener noreferrer"&gt;view it on the blog&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;… enquanto isso no resto do mundo …&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqcv7l2u82sdrlo150o30.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqcv7l2u82sdrlo150o30.gif" alt="Cena da série animada South Park" width="480" height="270"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Cena da série animada South Park&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Como já era de imaginar, com o avanço da tecnologia e da capacidade dos computadores, cada país utilizou essa capacidade extra para codificar seus próprios caracteres. O Japão, por exemplo, nem o ASCII usou. Outros codificadores, como o Shift JIS, utilizavam múltiplos bytes, e com tudo isso gerou-se uma gigantesca incompatibilidade.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Curiosidade: No Japão, existe a palavra mojibake (文字化け), que significa “caractere distorcido”. Isso acontecia devido aos problemas de codificação entre todos os alfabetos japoneses e também o latino.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Porém, mesmo com toda essa incompatibilidade durante os anos 1980 e 1990, quais eram as chances de uma empresa de Londres ter que mandar documentos constantemente para o Japão? Naquela época, a solução era simples: imprima e envie por fax!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgk5un7ojf0rmjef1errr.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgk5un7ojf0rmjef1errr.gif" alt="Cena da série animada Os Simpsons" width="480" height="366"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Cena da série animada Os Simpsons&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Então chegou a internet, e o que era ruim ficou ainda pior… Agora temos que lidar com documentos sendo enviados pela internet constantemente, e com o tempo foi formado o:&lt;/p&gt;

&lt;h2&gt;
  
  
  Unicode Consortium
&lt;/h2&gt;

&lt;p&gt;E como em um evento que pode se chamar de milagre do bom senso, durante as últimas décadas, foi formado um padrão com 154.998 caracteres, que cobre toda e qualquer língua que você possa imaginar: árabe, japonês, cirílico, chinês, coreano e até hieróglifos egípcios.&lt;/p&gt;

&lt;p&gt;O que eles fizeram de forma simplificada foi pegar centenas de milhares de números e atribuí-los a centenas de milhares de caracteres, ou seja, o número 35307 representará o caractere japonês 觫, o número 963 representará σ e assim por diante.&lt;/p&gt;

&lt;h3&gt;
  
  
  UTF-8
&lt;/h3&gt;

&lt;p&gt;Perfeito, agora nós temos centenas de milhares de números para representar todo e qualquer caractere, mas como vamos fazer isso com binário?&lt;/p&gt;

&lt;p&gt;Para representar um número nessas proporções, vamos precisar de pelo menos 32 bits para representar qualquer número dessa magnitude, o que agora trouxe problemas para o alfabeto inglês, porque o Unicode é compatível com ASCII, ou seja, “A” ainda é &lt;strong&gt;65&lt;/strong&gt; e “a” ainda é &lt;strong&gt;97&lt;/strong&gt;. Mas quando olhamos para o binário de 32 bits desses números, agora usamos 4x mais espaço para representar os mesmos caracteres.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;1&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;1&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;A&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;1&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;1&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;1&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;a&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Contando acima, há 25 zeros seguidos que estarão presentes em todo texto que utilizar caracteres latinos, e esse é só o primeiro dos nossos problemas. O segundo é que alguns sistemas antigos interpretam uma sequência de 8 zeros [&lt;code&gt;NULL&lt;/code&gt;] como fim de caractere, o famoso &lt;code&gt;\0&lt;/code&gt; do C.&lt;/p&gt;

&lt;p&gt;Então entra o UTF-8. A primeira coisa é: se a letra tiver numeração abaixo de 127, então você representa exatamente igual ao ASCII.&lt;/p&gt;

&lt;p&gt;Logo, o primeiro problema está resolvido: “A” ainda é &lt;strong&gt;65&lt;/strong&gt; e cabe em 8 bits. &lt;code&gt;01000001&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;E para números maiores que 127? Para isso você vai quebrar seu binário em 2 bytes.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;1&lt;/th&gt;
&lt;th&gt;2&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;110xxxxx&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;10xxxxxx&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;No byte 1, você tem o cabeçalho &lt;code&gt;110&lt;/code&gt;, que significa que esse caractere foi quebrado em 2 bytes. No byte 2, você começa com o cabeçalho de continuidade &lt;code&gt;10&lt;/code&gt;. Todos os outros bits restantes você vai preencher com o número que você quer representar.&lt;/p&gt;

&lt;p&gt;Para calcular, é só remover os cabeçalhos, unir todos os bits e o número resultante é o caractere Unicode. Você pode fazer isso até 4096. Passou disso? Sem problemas! Usando o cabeçalho &lt;code&gt;1110&lt;/code&gt; + 2 bytes, você tem 16 bits.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;1&lt;/th&gt;
&lt;th&gt;2&lt;/th&gt;
&lt;th&gt;3&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;1110xxxx&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;10xxxxxx&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;10xxxxxx&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Quer ir além? Tudo bem! O padrão suporta até o cabeçalho &lt;code&gt;1111110x&lt;/code&gt; + 6 bytes de continuidade.&lt;/p&gt;

&lt;h3&gt;
  
  
  Codificando UTF-8
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;Interactive Observable notebook widget — &lt;a href="https://jeffersonmourak.com/blog/unicode/" rel="noopener noreferrer"&gt;view it on the blog&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;É incrível como esse padrão consegue entregar:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;É compatível com os sistemas anteriores;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Não gasta espaço;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;E em nenhum momento na vida haverá 8 zeros seguidos em nenhuma parte de qualquer byte.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Além disso, outra razão que o fez se tornar o padrão mundial hoje em dia é que, para se mover entre caracteres, se você não sabe onde está, é só procurar o próximo cabeçalho, não precisa de índice.&lt;/p&gt;

&lt;p&gt;Já fazem alguns anos que o UTF-8 virou o padrão em toda comunicação pela internet, e o fato de hoje a pessoa japonesa média não precisar se preocupar com mojibake mais é por causa desse método genial de codificar texto.&lt;/p&gt;

&lt;h2&gt;
  
  
  Referencias
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=MijmeoH9LT4" rel="noopener noreferrer"&gt;Characters, Symbols and the Unicode Miracle - Computerphile (YouTube)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://datatracker.ietf.org/doc/html/rfc3629" rel="noopener noreferrer"&gt;UTF-8, a transformation format of ISO 10646 - ietf.org&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.joelonsoftware.com/2003/10/08/the-absolute-minimum-every-software-developer-absolutely-positively-must-know-about-unicode-and-character-sets-no-excuses/" rel="noopener noreferrer"&gt;The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!) - Joel Spolsky&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>unicode</category>
      <category>ascii</category>
      <category>utf8</category>
      <category>datatypes</category>
    </item>
    <item>
      <title>The Evolution of Digital Writing - From ASCII to the Wonders of UTF-8</title>
      <dc:creator>Jefferson Oliveira</dc:creator>
      <pubDate>Thu, 07 Aug 2025 12:29:04 +0000</pubDate>
      <link>https://dev.to/jeffersonmourak/the-evolution-of-digital-writing-from-ascii-to-the-wonders-of-utf-8-3ijg</link>
      <guid>https://dev.to/jeffersonmourak/the-evolution-of-digital-writing-from-ascii-to-the-wonders-of-utf-8-3ijg</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;Hey Y’all! This is a translation of my blog post originally written in Portuguese.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Have you ever wondered how computers transform letters, numbers, and emojis into zeros and ones that they can understand? Just like us humans assign meanings to letters of the alphabet, the computer does the same. Let’s explore here two of the most popular text encoding standards.&lt;/p&gt;

&lt;h2&gt;
  
  
  ASCII
&lt;/h2&gt;

&lt;p&gt;Developed in the 1960s, ASCII (American Standard Code for Information Interchange) has a very simple premise: using only 7 bits, you can represent 127 numbers, reserving the first 32 numbers in the sequence for important writing commands. The rest is filled with letters, numbers, and some punctuation marks.&lt;/p&gt;

&lt;p&gt;The people involved in developing the standard did it in such a way that the alphabet sequence could help with decoding.&lt;/p&gt;

&lt;p&gt;For example, the character for the number “0” is &lt;strong&gt;48&lt;/strong&gt; , which, represented in 7 bits, becomes &lt;code&gt;011 0000&lt;/code&gt;. Just like:&lt;/p&gt;

&lt;p&gt;1 → &lt;code&gt;011 0001&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;2 → &lt;code&gt;011 0010&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;3 → &lt;code&gt;011 0011&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;If you notice, the last 4 bits are in sequence. So, to find out what the integer is in ASCII, you just subtract 011 0000 (decimal: 48).&lt;/p&gt;

&lt;p&gt;In the same way, the letters of the alphabet: “A” is &lt;strong&gt;65&lt;/strong&gt; → 100 0001 and “a” is &lt;strong&gt;97&lt;/strong&gt; → 110 0001. With this, it was possible to encode all the letters of the English alphabet 🇬🇧.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Interactive Observable notebook widget — &lt;a href="https://jeffersonmourak.com/blog/unicode-en/" rel="noopener noreferrer"&gt;view it on the blog&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;… meanwhile in the rest of the world …&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqcv7l2u82sdrlo150o30.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqcv7l2u82sdrlo150o30.gif" alt="Scene from South Park series" width="480" height="270"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Scene from South Park series&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;As you might imagine, with the advancement of technology and computer capacity, each country used this extra capacity to encode their own characters. Japan, for example, didn’t even use ASCII. Other encoders, like Shift JIS, used multiple bytes, and with all this, a gigantic incompatibility was generated.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Fun fact: In Japan, there’s the word mojibake (文字化け), which means “distorted character”. This happened due to encoding problems between all Japanese alphabets and also the Latin one.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;However, even with all this incompatibility during the 1980s and 1990s, what were the chances of a London company having to constantly send documents to Japan? At that time, the solution was simple: print and send by fax!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgk5un7ojf0rmjef1errr.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgk5un7ojf0rmjef1errr.gif" alt="Scene from The Simpsons Series" width="480" height="366"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Scene from The Simpsons Series&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Then the internet came, and what was bad got even worse… Now we have to deal with documents being constantly sent over the internet, and over time the following was formed:&lt;/p&gt;

&lt;h2&gt;
  
  
  Unicode Consortium
&lt;/h2&gt;

&lt;p&gt;And as in an event that could be called a miracle of common sense, over the last few decades, a standard was formed with 154,998 characters, covering every language you can imagine: Arabic, Japanese, Cyrillic, Chinese, Korean, and even Egyptian hieroglyphs.&lt;/p&gt;

&lt;p&gt;What they did in a simplified way was take hundreds of thousands of numbers and assign them to hundreds of thousands of characters, that is, the number 35307 will represent the Japanese character 觫, the number 963 will represent σ, and so on.&lt;/p&gt;

&lt;h3&gt;
  
  
  UTF-8
&lt;/h3&gt;

&lt;p&gt;Perfect, now we have hundreds of thousands of numbers to represent every possible character, but how are we going to do this with binary?&lt;/p&gt;

&lt;p&gt;To represent a number in these proportions, we’ll need at least 32 bits to represent any number of that magnitude, which now brought problems for the English alphabet, because Unicode is compatible with ASCII, meaning “A” is still &lt;strong&gt;65&lt;/strong&gt; and “a” is still &lt;strong&gt;97&lt;/strong&gt;. But when we look at the 32-bit binary of these numbers, we now use 4x more space to represent the same characters.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;1&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;1&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;A&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;1&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;1&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;1&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;a&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Counting above, there are 25 consecutive zeros that will be present in every text that uses Latin characters, and that’s just the first of our problems. The second is that some old systems interpret a sequence of 8 zeros [&lt;code&gt;NULL&lt;/code&gt;] as the end of a character, the famous &lt;code&gt;\0&lt;/code&gt; in C.&lt;/p&gt;

&lt;p&gt;So UTF-8 comes in. The first thing is: if the letter has a number below 127, then you represent it exactly the same as ASCII.&lt;/p&gt;

&lt;p&gt;So the first problem is solved: “A” is still &lt;strong&gt;65&lt;/strong&gt; and fits in 8 bits. &lt;code&gt;01000001&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;And for numbers greater than 127? For that, you’ll break your binary into 2 bytes.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;1&lt;/th&gt;
&lt;th&gt;2&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;110xxxxx&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;10xxxxxx&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;In byte 1, you have the header &lt;code&gt;110&lt;/code&gt;, which means this character was broken into 2 bytes. In byte 2, you start with the continuation header &lt;code&gt;10&lt;/code&gt;. All other remaining bits you’ll fill with the number you want to represent.&lt;/p&gt;

&lt;p&gt;To calculate, just remove the headers, join all the bits, and the resulting number is the Unicode character. You can do this up to 4096. Beyond that? No problem! Using the header &lt;code&gt;1110&lt;/code&gt; + 2 bytes, you have 16 bits.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;1&lt;/th&gt;
&lt;th&gt;2&lt;/th&gt;
&lt;th&gt;3&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;1110xxxx&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;10xxxxxx&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;10xxxxxx&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Want to go further? That’s fine! The standard supports up to the header &lt;code&gt;1111110x&lt;/code&gt; + 6 continuation bytes.&lt;/p&gt;

&lt;h3&gt;
  
  
  Encoding UTF-8
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;Interactive Observable notebook widget — &lt;a href="https://jeffersonmourak.com/blog/unicode-en/" rel="noopener noreferrer"&gt;view it on the blog&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;It’s amazing how this standard manages to deliver:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;It’s compatible with previous systems;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It doesn’t waste space;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;And at no point in life will there be 8 consecutive zeros in any part of any byte.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Additionally, another reason that made it become the world standard today is that, to move between characters, if you don’t know where you are, you just look for the next header, you don’t need an index.&lt;/p&gt;

&lt;p&gt;It’s been several years since UTF-8 became the standard in all internet communication, and the fact that today the average Japanese person doesn’t need to worry about mojibake anymore is because of this brilliant method of encoding text.&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=MijmeoH9LT4" rel="noopener noreferrer"&gt;Characters, Symbols and the Unicode Miracle - Computerphile (YouTube)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://datatracker.ietf.org/doc/html/rfc3629" rel="noopener noreferrer"&gt;UTF-8, a transformation format of ISO 10646 - ietf.org&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://joelonsoftware.com/2003/10/08/the-absolute-minimum-every-software-developer-absolutely-positively-must-know-about-unicode-and-character-sets-no-excuses/" rel="noopener noreferrer"&gt;The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!) - Joel Spolsky&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>unicode</category>
      <category>ascii</category>
      <category>utf8</category>
    </item>
    <item>
      <title>A Tela é o Quadro - Desenhando fontes com matemática</title>
      <dc:creator>Jefferson Oliveira</dc:creator>
      <pubDate>Thu, 31 Jul 2025 13:29:04 +0000</pubDate>
      <link>https://dev.to/jeffersonmourak/a-tela-e-o-quadro-desenhando-fontes-com-matematica-4063</link>
      <guid>https://dev.to/jeffersonmourak/a-tela-e-o-quadro-desenhando-fontes-com-matematica-4063</guid>
      <description>&lt;p&gt;No sábado, 26 de julho de 2025, apresentei uma palestra sobre renderização de fontes no Google I/O Extended Natal. Devido à correria do dia a dia, não consegui mostrar muitos exemplos práticos interativos. Este artigo serve justamente para isso: vamos explorar um pouco sobre como o texto que você está lendo é formado na sua tela.&lt;/p&gt;

&lt;p&gt;Para começar, falaremos sobre Bitmaps. Esta é a forma mais ingênua de desenhar fontes, pois um bitmap nada mais é do que uma imagem pronta. Abaixo, por exemplo, temos uma letra que ocupa um espaço de 6 pixels de altura por 6 pixels de largura.&lt;/p&gt;

&lt;p&gt;No momento, você consegue visualizar facilmente porque o tamanho dos pixels está em 10 pixels. No entanto, se você alterar o tamanho para 1 pixel, verá que não é possível ler o que está na tela."&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Interactive p5 widget — &lt;a href="https://jeffersonmourak.com/blog/font-rendering/" rel="noopener noreferrer"&gt;view it on the blog&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Como mostrado, o maior problema das fontes de bitmap é que elas não são escaláveis. Ou seja, para que possamos mudar o tamanho das fontes, teríamos que:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Criar uma nova fonte com cada uma das letras desenhadas no novo tamanho.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Rasterizar a fonte em uma outra escala.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Vamos ver o que acontece na segunda opção.&lt;/p&gt;

&lt;p&gt;Essa é uma função simples de escala. Ela recebe como parâmetros os dados da letra que você quer desenhar e a escala na qual deseja aumentar.&lt;/p&gt;

&lt;p&gt;Ela funciona simplesmente duplicando os pixels existentes tanto no eixo &lt;em&gt;X&lt;/em&gt; quanto no &lt;em&gt;Y&lt;/em&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;scaleGlyph&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;glyph&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;scale&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;newWidth&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ceil&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;glyph&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;width&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;scale&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;newHeight&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ceil&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;glyph&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;height&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;scale&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;newPixels&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;from&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;length&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;newHeight&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;
    &lt;span class="nc"&gt;Array&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;newWidth&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;fill&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;glyph&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;height&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;glyph&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;width&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;glyph&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;pixels&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
      &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;newX&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;floor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;scale&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;newY&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;floor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;y&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;scale&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;dy&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;dy&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;scale&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;dy&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;dx&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;dx&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;scale&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;dx&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;newY&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;dy&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;newHeight&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;newX&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;dx&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;newWidth&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nx"&gt;newPixels&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;newY&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;dy&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="nx"&gt;newX&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;dx&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
          &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;newWidth&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;newHeight&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;pixels&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;newPixels&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;O problema desse tipo de escala é que as fontes acabam obtendo um aspecto de bloco, o que traz a sensação de uma imagem com baixa resolução.&lt;/p&gt;

&lt;p&gt;Outra forma é aplicando uma escala utilizando interpolação linear. Essa técnica consiste em tirar uma média de todos os pontos originais ao redor, em vez de simplesmente copiar o bloco inteiro, repetindo cegamente o que há no pixel. No entanto, isso agora resulta em um aspecto de imagem borrada, e essa característica se acentua quanto maior a diferença entre o tamanho original e o tamanho final.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;lerp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;v0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;x1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;v1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x0&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;x1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;v0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;v0&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;v1&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;v0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;x0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x1&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;x0&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;bilinearInterpolate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;Q11&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Q21&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Q12&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Q22&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="nx"&gt;Q11&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="nx"&gt;Q12&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt;
    &lt;span class="nx"&gt;Q21&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="nx"&gt;Q22&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt;
    &lt;span class="nx"&gt;Q11&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;y&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="nx"&gt;Q21&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;y&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt;
    &lt;span class="nx"&gt;Q12&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;y&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="nx"&gt;Q22&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;y&lt;/span&gt;
  &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
      &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Error: The provided points do not form a proper rectangle for bilinear interpolation.&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
    &lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;x1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;Q11&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;x2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;Q21&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;y1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;Q11&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;y2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;Q12&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;R1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;lerp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Q11&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;x2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Q21&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;R2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;lerp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Q12&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;x2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Q22&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;P&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;lerp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;y1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;R1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;y2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;R2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;P&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Com isso temos os exemplos a baixo,&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Interactive p5 widget — &lt;a href="https://jeffersonmourak.com/blog/font-rendering/" rel="noopener noreferrer"&gt;view it on the blog&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Como utilizar uma só fonte para vários tamanhos?
&lt;/h2&gt;

&lt;p&gt;Na matemática, existem equações que desenham um gráfico na tela. Os exemplos mais comuns são:&lt;/p&gt;

&lt;h3&gt;
  
  
  Função quadrática
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;Interactive Observable notebook widget — &lt;a href="https://jeffersonmourak.com/blog/font-rendering/" rel="noopener noreferrer"&gt;view it on the blog&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Função inversa multiplicativa
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;Interactive Observable notebook widget — &lt;a href="https://jeffersonmourak.com/blog/font-rendering/" rel="noopener noreferrer"&gt;view it on the blog&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Manipulando a curva
&lt;/h3&gt;

&lt;p&gt;Para mover nossas equações, podemos somar um valor qualquer após o resultado da exponenciação e, assim, movemos nossa equação no eixo &lt;em&gt;Y&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Interactive Observable notebook widget — &lt;a href="https://jeffersonmourak.com/blog/font-rendering/" rel="noopener noreferrer"&gt;view it on the blog&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Para mover nossa equação na horizontal, adicionamos esse valor antes de elevá-lo ao quadrado.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Interactive Observable notebook widget — &lt;a href="https://jeffersonmourak.com/blog/font-rendering/" rel="noopener noreferrer"&gt;view it on the blog&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Então, já temos uma maneira de representar nossas curvas utilizando equações matemáticas.&lt;/p&gt;

&lt;p&gt;Mas antes de desenharmos, vamos aprender sobre mais uma coisa.&lt;/p&gt;

&lt;h2&gt;
  
  
  Curvas de Bézier
&lt;/h2&gt;

&lt;p&gt;Ela é uma curva polinomial expressa como a interpolação linear entre alguns pontos representativos, chamados de pontos de controle.&lt;/p&gt;

&lt;p&gt;No exemplo abaixo, temos 3 pontos: &lt;em&gt;P0&lt;/em&gt;, &lt;em&gt;P1&lt;/em&gt; e &lt;em&gt;P2&lt;/em&gt;, onde &lt;em&gt;P0&lt;/em&gt; e &lt;em&gt;P2&lt;/em&gt; são os pontos representativos e &lt;em&gt;P1&lt;/em&gt; é o ponto de controle, você pode mover os exemplos abaixo e ver o resultado.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Interactive p5 widget — &lt;a href="https://jeffersonmourak.com/blog/font-rendering/" rel="noopener noreferrer"&gt;view it on the blog&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Desenhando uma letra com vetores
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;Interactive p5 widget — &lt;a href="https://jeffersonmourak.com/blog/font-rendering/" rel="noopener noreferrer"&gt;view it on the blog&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Com o conceito de Bézier, fica até intuitivo como podemos desenhar uma letra usando matemática: basta organizar pontos em sequência e misturar linhas retas com curvas de Bézier, fazendo com que o &lt;em&gt;P2&lt;/em&gt; de uma termine exatamente onde começa o &lt;em&gt;P0&lt;/em&gt; da outra.&lt;/p&gt;

&lt;p&gt;Aliás, uma reta também pode ser feita com Bézier; basta alinhar todos os pontos. Dessa forma, fica ainda mais claro como a interpolação atua na curva de Bézier.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Interactive p5 widget — &lt;a href="https://jeffersonmourak.com/blog/font-rendering/" rel="noopener noreferrer"&gt;view it on the blog&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Com isso, já podemos agora pensar em como transformar isso em um bitmap. Para fazer isso, precisamos primeiramente rasterizar essa fonte, começando por traduzir as curvas de Bézier em linhas compatíveis com a resolução da tela. Isso acontece porque a tela do computador é uma matriz de pixels; logo, precisamos transformar curvas em pixels legíveis ao olho humano.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Interactive p5 widget — &lt;a href="https://jeffersonmourak.com/blog/font-rendering/" rel="noopener noreferrer"&gt;view it on the blog&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Feito isso, a última coisa que se precisa é preencher a letra. Essa parte pode ser feita por um processo chamado scanline, que consiste em lançar um raio e contar quantas vezes esse raio vai tocar uma das paredes da letra. Se o número de toques for par, o pixel está representado fora da letra; se for ímpar, ele está dentro.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffr6zivulmle6flescak3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffr6zivulmle6flescak3.png" alt="2 intersections with the letter"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;2 Interseções com a letra&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4s4507m58ka31hngn87a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4s4507m58ka31hngn87a.png" alt="2 and 3 intersections with the letter"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;2 e 3 Interseções com a letra&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftgb20rmzhb440mfyw69u.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftgb20rmzhb440mfyw69u.png" alt="2, 3, and 4 intersections with the letter"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;2, 3 e 4 Interseções com a letra&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Perceba que, no exemplo da letra ‘O’, há uma falha na renderização. Ela está aí de propósito: o processo de renderizar fontes é complicado e cheio de edge cases que só aumentam quanto mais aprofundamos no assunto.&lt;/p&gt;

&lt;p&gt;O que quero demonstrar com essa falha é que, além de contar quantas vezes sua linha corta a letra, deve-se também estar ciente se a linha está cortando ela mesma novamente.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Interactive p5 widget — &lt;a href="https://jeffersonmourak.com/blog/font-rendering/" rel="noopener noreferrer"&gt;view it on the blog&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Bem, e com isso, concluímos esta etapa do processo de renderização das fontes. Daqui a uns dias, vou publicar outros dois artigos sobre o tema para complementar o assunto da palestra. Eles serão sobre Unicode e Text Shaping.&lt;/p&gt;

&lt;p&gt;Muito obrigado, e até a próxima! 😊&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fis28fnn3bjfop740a2rz.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fis28fnn3bjfop740a2rz.gif" alt="Jimmy Fallon escorregando e dando tchau"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Jimmy Fallon escorregando e dando tchau&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Referencias
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=qcMuyHzhvpI" rel="noopener noreferrer"&gt;A Brief look at Text Rendering - VoxelRifts (YouTube)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=SO83KQuuZvg" rel="noopener noreferrer"&gt;Coding Adventure: Rendering Text -Sebastian Lague (YouTube)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=LaYPoMPRSlk" rel="noopener noreferrer"&gt;The Math Behind Font Rasterization | How it Works - GamesWithGame (YouTube)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://faultlore.com/blah/text-hates-you/" rel="noopener noreferrer"&gt;Text Rendering Hates You - Aria Desires&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;[Multi-channel signed distance field generator - Viktor Chlumský&lt;a href="https://dev.toGitHub"&gt;Valve&lt;/a&gt;](&lt;a href="https://github.com/Chlumsky/msdfgen" rel="noopener noreferrer"&gt;https://github.com/Chlumsky/msdfgen&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/harfbuzz/harfbuzz" rel="noopener noreferrer"&gt;Harfbuzz[Google] - (GitHub)&lt;/a&gt;
&amp;lt;!--
p5.js is loaded here as a plain global so the inline observable:notebook
cells in this post (the &lt;code&gt;p5(sketch)&lt;/code&gt; wrapper at id="0") can reference
&lt;code&gt;window.p5&lt;/code&gt; directly without going through Observable's &lt;code&gt;require()&lt;/code&gt;. A
non-deferred  blocks parsing where it sits, so by the time the
notebook&amp;amp;#39;s module bundle runs (module scripts are deferred until the
document finishes parsing), &amp;lt;code&amp;gt;window.p5&amp;lt;/code&amp;gt; is guaranteed to exist.
--&amp;amp;gt;&amp;lt;script src="https://cdn.jsdelivr.net/npm/p5@1.11.3/lib/p5.min.js"&amp;gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>fontrendering</category>
      <category>font</category>
      <category>computergraphics</category>
    </item>
    <item>
      <title>The Screen is the Canvas - Drawing Fonts with Mathematics</title>
      <dc:creator>Jefferson Oliveira</dc:creator>
      <pubDate>Thu, 31 Jul 2025 12:29:04 +0000</pubDate>
      <link>https://dev.to/jeffersonmourak/the-screen-is-the-canvas-drawing-fonts-with-mathematics-4035</link>
      <guid>https://dev.to/jeffersonmourak/the-screen-is-the-canvas-drawing-fonts-with-mathematics-4035</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;Hey Y’all! This is a translation of my blog post originally written in Portuguese.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;On Saturday, July 26, 2025, I presented a lecture on font rendering at Google I/O Extended Natal. Due to the rush of daily life, I couldn’t show many interactive practical examples. This article serves exactly that purpose: let’s explore a bit about how the text you’re reading is formed on your screen.&lt;/p&gt;

&lt;p&gt;To start, we’ll talk about Bitmaps. This is the most naive way to draw fonts, as a bitmap is nothing more than a ready-made image. Below, for example, we have a letter that occupies a space of 6 pixels in height by 6 pixels in width.&lt;/p&gt;

&lt;p&gt;At the moment, you can easily visualize it because the pixel size is set to 10 pixels. However, if you change the size to 1 pixel, you’ll see that it’s not possible to read what’s on the screen.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Interactive p5 widget — &lt;a href="https://jeffersonmourak.com/blog/font-rendering-en/" rel="noopener noreferrer"&gt;view it on the blog&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;As shown, the biggest problem with bitmap fonts is that they are not scalable. That is, to change the font size, we would have to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Create a new font with each letter drawn in the new size.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Rasterize the font at another scale.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let’s see what happens in the second option.&lt;/p&gt;

&lt;p&gt;This is a simple scaling function. It receives as parameters the data of the letter you want to draw and the scale at which you want to increase it.&lt;/p&gt;

&lt;p&gt;It works simply by duplicating existing pixels on both the &lt;em&gt;X&lt;/em&gt; and &lt;em&gt;Y&lt;/em&gt; axes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;scaleGlyph&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;glyph&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;scale&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;newWidth&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ceil&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;glyph&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;width&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;scale&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;newHeight&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ceil&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;glyph&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;height&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;scale&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;newPixels&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;from&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;length&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;newHeight&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;
    &lt;span class="nc"&gt;Array&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;newWidth&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;fill&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;glyph&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;height&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;glyph&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;width&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;glyph&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;pixels&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
      &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;newX&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;floor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;scale&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;newY&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;floor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;y&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;scale&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;dy&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;dy&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;scale&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;dy&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;dx&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;dx&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;scale&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;dx&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;newY&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;dy&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;newHeight&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;newX&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;dx&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;newWidth&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nx"&gt;newPixels&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;newY&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;dy&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="nx"&gt;newX&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;dx&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
          &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;newWidth&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;newHeight&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;pixels&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;newPixels&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The problem with this type of scaling is that fonts end up getting a blocky appearance, which brings the feeling of a low-resolution image.&lt;/p&gt;

&lt;p&gt;Another way is by applying scaling using linear interpolation. This technique consists of taking an average of all the original points around, instead of simply copying the entire block, blindly repeating what’s in the pixel. However, this now results in a blurred image appearance, and this characteristic becomes more pronounced the greater the difference between the original size and the final size.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;lerp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;v0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;x1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;v1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x0&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;x1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;v0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;v0&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;v1&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;v0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;x0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x1&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;x0&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;bilinearInterpolate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;Q11&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Q21&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Q12&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Q22&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="nx"&gt;Q11&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="nx"&gt;Q12&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt;
    &lt;span class="nx"&gt;Q21&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="nx"&gt;Q22&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt;
    &lt;span class="nx"&gt;Q11&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;y&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="nx"&gt;Q21&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;y&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt;
    &lt;span class="nx"&gt;Q12&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;y&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="nx"&gt;Q22&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;y&lt;/span&gt;
  &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
      &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Error: The provided points do not form a proper rectangle for bilinear interpolation.&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
    &lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;x1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;Q11&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;x2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;Q21&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;y1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;Q11&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;y2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;Q12&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;R1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;lerp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Q11&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;x2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Q21&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;R2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;lerp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Q12&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;x2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Q22&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;P&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;lerp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;y1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;R1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;y2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;R2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;P&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With this we have the examples below:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Interactive p5 widget — &lt;a href="https://jeffersonmourak.com/blog/font-rendering-en/" rel="noopener noreferrer"&gt;view it on the blog&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How to use one font for multiple sizes?
&lt;/h2&gt;

&lt;p&gt;In mathematics, there are equations that draw a graph on the screen. The most common examples are:&lt;/p&gt;

&lt;h3&gt;
  
  
  Quadratic function
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;Interactive Observable notebook widget — &lt;a href="https://jeffersonmourak.com/blog/font-rendering-en/" rel="noopener noreferrer"&gt;view it on the blog&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Multiplicative inverse function
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;Interactive Observable notebook widget — &lt;a href="https://jeffersonmourak.com/blog/font-rendering-en/" rel="noopener noreferrer"&gt;view it on the blog&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Manipulating the curve
&lt;/h3&gt;

&lt;p&gt;To move our equations, we can add any value after the result of the exponentiation, and thus we move our equation on the &lt;em&gt;Y&lt;/em&gt; axis.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Interactive Observable notebook widget — &lt;a href="https://jeffersonmourak.com/blog/font-rendering-en/" rel="noopener noreferrer"&gt;view it on the blog&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;To move our equation horizontally, we add that value before squaring it.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Interactive Observable notebook widget — &lt;a href="https://jeffersonmourak.com/blog/font-rendering-en/" rel="noopener noreferrer"&gt;view it on the blog&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;So, we already have a way to represent our curves using mathematical equations.&lt;/p&gt;

&lt;p&gt;But before we draw, let’s learn about one more thing.&lt;/p&gt;

&lt;h2&gt;
  
  
  Bézier curves
&lt;/h2&gt;

&lt;p&gt;It’s a polynomial curve expressed as the linear interpolation between some representative points, called control points.&lt;/p&gt;

&lt;p&gt;In the example below, we have 3 points: &lt;em&gt;P0&lt;/em&gt;, &lt;em&gt;P1&lt;/em&gt; and &lt;em&gt;P2&lt;/em&gt;, where &lt;em&gt;P0&lt;/em&gt; and &lt;em&gt;P2&lt;/em&gt; are the representative points and &lt;em&gt;P1&lt;/em&gt; is the control point, you can move the examples below and see the result.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Interactive p5 widget — &lt;a href="https://jeffersonmourak.com/blog/font-rendering-en/" rel="noopener noreferrer"&gt;view it on the blog&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Drawing a letter with vectors
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;Interactive p5 widget — &lt;a href="https://jeffersonmourak.com/blog/font-rendering-en/" rel="noopener noreferrer"&gt;view it on the blog&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;With the Bézier concept, it becomes quite intuitive how we can draw a letter using mathematics: just organize points in sequence and mix straight lines with Bézier curves, making the &lt;em&gt;P2&lt;/em&gt; of one end exactly where the &lt;em&gt;P0&lt;/em&gt; of the other begins.&lt;/p&gt;

&lt;p&gt;By the way, a straight line can also be made with Bézier; just align all the points. This way, it becomes even clearer how interpolation acts on the Bézier curve.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Interactive p5 widget — &lt;a href="https://jeffersonmourak.com/blog/font-rendering-en/" rel="noopener noreferrer"&gt;view it on the blog&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;With this, we can now think about how to transform this into a bitmap. To do this, we first need to rasterize this font, starting by translating the Bézier curves into lines compatible with the screen resolution. This happens because the computer screen is a matrix of pixels; therefore, we need to transform curves into pixels readable to the human eye.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Interactive p5 widget — &lt;a href="https://jeffersonmourak.com/blog/font-rendering-en/" rel="noopener noreferrer"&gt;view it on the blog&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Once this is done, the last thing needed is to fill the letter. This part can be done by a process called scanline, which consists of launching a ray and counting how many times that ray will touch one of the walls of the letter. If the number of touches is even, the pixel is represented outside the letter; if it’s odd, it’s inside.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7bc5rek1sr2v7ga3rv8k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7bc5rek1sr2v7ga3rv8k.png" alt="2 intersections with the letter"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;2 intersections with the letter&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu6cwrocve0hju2n4ix4o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu6cwrocve0hju2n4ix4o.png" alt="2 and 3 intersections with the letter"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;2 and 3 intersections with the letter&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5u085ylbcr12g1qdwsg1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5u085ylbcr12g1qdwsg1.png" alt="2, 3, and 4 intersections with the letter"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;2, 3, and 4 intersections with the letter&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Notice that in the example of the letter ‘O’, there’s a rendering flaw. It’s there on purpose: the process of rendering fonts is complicated and full of edge cases that only increase the more we delve into the subject.&lt;/p&gt;

&lt;p&gt;What I want to demonstrate with this flaw is that, besides counting how many times your line cuts the letter, you should also be aware if the line is cutting itself again.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Interactive p5 widget — &lt;a href="https://jeffersonmourak.com/blog/font-rendering-en/" rel="noopener noreferrer"&gt;view it on the blog&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Well, and with this, we conclude this stage of the font rendering process. In a few days, I’ll publish two more articles on the topic to complement the lecture subject. They will be about Unicode and Text Shaping.&lt;/p&gt;

&lt;p&gt;Thank you very much, and see you next time! 😊&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fis28fnn3bjfop740a2rz.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fis28fnn3bjfop740a2rz.gif" alt="Jimmy Fallon sliding and waiving bye"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Jimmy Fallon sliding and waiving bye&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=qcMuyHzhvpI" rel="noopener noreferrer"&gt;A Brief look at Text Rendering - VoxelRifts (YouTube)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=SO83KQuuZvg" rel="noopener noreferrer"&gt;Coding Adventure: Rendering Text -Sebastian Lague (YouTube)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=LaYPoMPRSlk" rel="noopener noreferrer"&gt;The Math Behind Font Rasterization | How it Works - GamesWithGame (YouTube)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://faultlore.com/blah/text-hates-you/" rel="noopener noreferrer"&gt;Text Rendering Hates You - Aria Desires&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;[Multi-channel signed distance field generator - Viktor Chlumský&lt;a href="https://dev.toGitHub"&gt;Valve&lt;/a&gt;](&lt;a href="https://github.com/Chlumsky/msdfgen" rel="noopener noreferrer"&gt;https://github.com/Chlumsky/msdfgen&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/harfbuzz/harfbuzz" rel="noopener noreferrer"&gt;Harfbuzz[Google] - (GitHub)&lt;/a&gt;
&amp;lt;!--
p5.js is loaded here as a plain global so the inline &lt;code&gt;p5&lt;/code&gt; codeblocks
on this page can reference &lt;code&gt;window.p5&lt;/code&gt; directly. A non-deferred
 blocks parsing where it sits, so by the time any inline
module bundle runs, &amp;lt;code&amp;gt;window.p5&amp;lt;/code&amp;gt; is guaranteed to exist.
--&amp;amp;gt;&amp;lt;script src="https://cdn.jsdelivr.net/npm/p5@1.11.3/lib/p5.min.js"&amp;gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>fontrendering</category>
      <category>font</category>
      <category>computergraphics</category>
    </item>
    <item>
      <title>Lembra de mim?</title>
      <dc:creator>Jefferson Oliveira</dc:creator>
      <pubDate>Sun, 19 Jan 2025 11:27:04 +0000</pubDate>
      <link>https://dev.to/jeffersonmourak/lembra-de-mim-12a3</link>
      <guid>https://dev.to/jeffersonmourak/lembra-de-mim-12a3</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;Olá todo mundo, este é o terceiro artigo na série sobre computadores, e também o último com esse cabeçalho aqui, pois daqui para a frente é recomendado que você já tenha lido os dois artigos anteriores:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://jeffersonmourak.com/blog/logic-gates/" rel="noopener noreferrer"&gt;Portas lógicas&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://jeffersonmourak.com/blog/the-binary/" rel="noopener noreferrer"&gt;Prazer, Binário.&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;Nos artigos anteriores, nós vimos como portas lógicas podem ser usadas para fazer comparações e também calcular operações aritméticas, porém ainda não vimos como o computador pode guardar uma informação ao longo do tempo.&lt;/p&gt;

&lt;p&gt;Outra coisa que também iremos fazer aqui é categorizar cada tipo de chip: os que foram mostrados anteriormente são _ &lt;strong&gt;combinacionais&lt;/strong&gt; _, o que significa que eles não precisam de nada além de sinais nas suas entradas para poder computar um resultado, mas existem também os _ &lt;strong&gt;sequenciais&lt;/strong&gt; _. A diferença entre eles é que o sequencial depende não só dos sinais das entradas, mas também do valor anteriormente processado.&lt;/p&gt;

&lt;p&gt;Um jeito muito prático de usar portas lógicas para guardar informações é usando um chip chamado de _ &lt;strong&gt;flip-flop&lt;/strong&gt; _, que está representado abaixo. Ele contém 2 entradas: a de cima &lt;code&gt;set&lt;/code&gt; e a de baixo &lt;code&gt;reset&lt;/code&gt; (você pode clicar no circuito abaixo para interagir com eles).&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Interactive circ widget — &lt;a href="https://jeffersonmourak.com/blog/memory/" rel="noopener noreferrer"&gt;view it on the blog&lt;/a&gt;.&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;╭───────╮ ╭───╮ ╭───╮ ╭───╮
│ reset ├○───▶┤NOT├○╮ ╭──▶┤ │ ╭──▶┤LED│
╰───────╯ ╰───╯ │ │ │AND├○● ╰───╯
                    ╰─────┼──▶┤ │ │        
                          │ ╰───╯ │        
            ╭─────────────┼─────────╯        
╭─────╮ │ ╭─────────╮ │                  
│ set ├○╮ ╰▶┤ │ │                  
╰─────╯ │ │[or:_or_]├○╯                  
        ╰────▶┤ │                    
              ╰─────────╯                    
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Se parar para analisar, é bem simples: seguindo a trilha do &lt;code&gt;set&lt;/code&gt;, verá que há duas portas lógicas no caminho, uma &lt;code&gt;OR&lt;/code&gt; e uma &lt;code&gt;AND&lt;/code&gt;. Uma das entradas da porta &lt;code&gt;OR&lt;/code&gt; está ligada com o resultado da &lt;code&gt;AND&lt;/code&gt; lá no fim do chip. Essa combinação faz com que, quando temos &lt;strong&gt;0&lt;/strong&gt; e é nos dado um valor &lt;strong&gt;1&lt;/strong&gt; , a porta &lt;code&gt;OR&lt;/code&gt; vai resultar em &lt;strong&gt;1&lt;/strong&gt; , e a &lt;code&gt;AND&lt;/code&gt; também.&lt;/p&gt;

&lt;p&gt;Porém, quando removemos o sinal do &lt;code&gt;set&lt;/code&gt;, o valor que foi anteriormente colocado é persistido porque agora o &lt;code&gt;OR&lt;/code&gt; está mantendo o estado que mantém o &lt;code&gt;AND&lt;/code&gt; também no estado anterior. Problema resolvido, certo? Não! Perceba que nosso circuito agora está travado, pois não há como sair desse estado a não ser que o &lt;code&gt;AND&lt;/code&gt; passe a ter um outro valor, e é para isso que serve a porta &lt;code&gt;reset&lt;/code&gt;: ela está ligada a um &lt;code&gt;NOT&lt;/code&gt;, ou seja, enquanto ela estiver desligada (0), o seu resultado vai ser 1 (ligado), e vice-versa.&lt;/p&gt;

&lt;p&gt;Uma evolução que podemos fazer no _ &lt;strong&gt;flip-flop&lt;/strong&gt; _ é transformá-lo em um _ &lt;strong&gt;Registrador&lt;/strong&gt; _. No registrador, podemos escolher se é ou não a hora de ler o nosso sinal e guardá-lo, e subsequentemente reescrevê-lo, e tudo isso ao nosso bel-prazer. Existem muitas formas de atingir esse chip, então vou usar a implementação demonstrada pelo &lt;a href="https://www.youtube.com/watch?v=I0-izyq6q5s" rel="noopener noreferrer"&gt;Sebastian Lague&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Nela, a gente só precisa adicionar mais 3 portas lógicas e pronto!&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Interactive circ widget — &lt;a href="https://jeffersonmourak.com/blog/memory/" rel="noopener noreferrer"&gt;view it on the blog&lt;/a&gt;.&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;╭──────╮ ╭───╮ ╭───╮ ╭───╮ ╭───╮ ╭───╮ ╭───╮ ╭───╮ ╭───╮
│ data ├○──●───▶┤ │ ╭─▶┤NOT├○┬──▶┤NOT├○───▶┤ │ ╭──▶┤NOT├○╮ ╭▶┤ │ ╭──▶┤NOT├○●──▶┤LED│
╰──────╯ │ │AND├○─╯ ╰───╯ │ ╰───╯ │AND├○╯ ╰───╯ │ │ │AND├○╯ ╰───╯ │ ╰───╯
           │╭──▶┤ │ │ ╭▶┤ │ ╰─┼▶┤ │ │        
           ││ ╰───╯ │ │ ╰───╯ │ ╰───╯ │        
           ││ ├───────────┼───────────────────╯ │        
╭─────────╮││ ╭───╮ ╭───╮ │ │ │        
│ enabled ├○┼──▶┤NOT├○───▶┤ │ │ ╰─────────────────────────────────────╯        
╰─────────╯ │ ╰───╯ │AND├○╯                                                          
            ╰────────────▶┤ │                                                            
                          ╰───╯                                                            
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Se a gente destrinchar um pouco, o que acontece é o seguinte: a entrada superior, que agora chamaremos de &lt;code&gt;data&lt;/code&gt;, só será salva no _ &lt;strong&gt;flip-flop&lt;/strong&gt; _ quando a entrada inferior, que também mudou o nome, agora se chama &lt;code&gt;enabled&lt;/code&gt;. Ou seja, em vez de usar duas entradas, uma para salvar e outra para apagar, essa combinação de &lt;code&gt;AND&lt;/code&gt;s e &lt;code&gt;NOT&lt;/code&gt; escolhe qual operação será feita.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Se &lt;code&gt;data&lt;/code&gt; = 1 e &lt;code&gt;enabled&lt;/code&gt; = 1, então é a mesma coisa que ligar a entrada &lt;code&gt;set&lt;/code&gt; do _ &lt;strong&gt;flip-flop&lt;/strong&gt; _.&lt;/li&gt;
&lt;li&gt;Se &lt;code&gt;data&lt;/code&gt; = 0 e &lt;code&gt;enabled&lt;/code&gt; = 1, então é a mesma coisa que ligar a entrada &lt;code&gt;reset&lt;/code&gt; do _ &lt;strong&gt;flip-flop&lt;/strong&gt; _. Perceba que o &lt;code&gt;enabled&lt;/code&gt; precisa sempre estar ativado para que possa salvar o sinal que foi colocado em &lt;code&gt;data&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Uma outra coisa que podemos fazer é pegar inspiração no artigo anterior, que no final a gente aprende que, se juntarmos vários Adders, nós podemos fazer contas com múltiplos dígitos. Na memória é do mesmo jeito: juntando vários registradores, você pode fornecer uma entrada para cada &lt;code&gt;data&lt;/code&gt; e compartilhar o sinal do &lt;code&gt;enabled&lt;/code&gt;, e assim você pode salvar os valores de um número binário inteiro.&lt;/p&gt;

&lt;p&gt;Por enquanto, a gente se despede por aqui, até a próxima 😄&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxg2g1p3mcez463cbnc54.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxg2g1p3mcez463cbnc54.gif" alt="Xauzinho!"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Xauzinho!&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Referências
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=I0-izyq6q5s" rel="noopener noreferrer"&gt;How Do Computers Remember? (YouTube)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=KM0DdEaY5sY" rel="noopener noreferrer"&gt;SR latch (YouTube)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=peCh_859q7Q" rel="noopener noreferrer"&gt;D latch&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=HjneAhCy2N4" rel="noopener noreferrer"&gt;HOW TRANSISTORS RUN CODE? (YouTube)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.nand2tetris.org/" rel="noopener noreferrer"&gt;From Nand to Tetris&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>cpu</category>
      <category>memory</category>
      <category>combinational</category>
      <category>sequential</category>
    </item>
    <item>
      <title>Remember me?</title>
      <dc:creator>Jefferson Oliveira</dc:creator>
      <pubDate>Sun, 19 Jan 2025 10:27:04 +0000</pubDate>
      <link>https://dev.to/jeffersonmourak/remember-me-31jg</link>
      <guid>https://dev.to/jeffersonmourak/remember-me-31jg</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;Hey Y’all! This is a translation of my blog post originally written in Portuguese.&lt;/p&gt;

&lt;p&gt;Hello everyone, this is the third article in the series about computers, and also the last one with this header here, because from here on it’s recommended that you have already read the two previous articles:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://jeffersonmourak.com/blog/logic-gates/" rel="noopener noreferrer"&gt;Logic gates&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://jeffersonmourak.com/blog/the-binary/" rel="noopener noreferrer"&gt;Pleasure to meet you, Binary.&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;In the previous articles, we saw how logic gates can be used to make comparisons and also calculate arithmetic operations, but we haven’t yet seen how the computer can store information over time.&lt;/p&gt;

&lt;p&gt;Another thing we’ll do here is categorize each type of chip: the ones shown previously are _ &lt;strong&gt;combinational&lt;/strong&gt; _, which means they don’t need anything beyond signals at their inputs to be able to compute a result, but there are also _ &lt;strong&gt;sequential&lt;/strong&gt; _ ones. The difference between them is that sequential depends not only on the input signals, but also on the previously processed value.&lt;/p&gt;

&lt;p&gt;A very practical way to use logic gates to store information is using a chip called _ &lt;strong&gt;flip-flop&lt;/strong&gt; _, which is represented below. It contains 2 inputs: the top one &lt;code&gt;set&lt;/code&gt; and the bottom one &lt;code&gt;reset&lt;/code&gt; (you can click on the circuit below to interact with them).&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Interactive circ widget — &lt;a href="https://jeffersonmourak.com/blog/memory-en/" rel="noopener noreferrer"&gt;view it on the blog&lt;/a&gt;.&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;╭───────╮ ╭───╮ ╭───╮ ╭───╮
│ reset ├○───▶┤NOT├○╮ ╭──▶┤ │ ╭──▶┤LED│
╰───────╯ ╰───╯ │ │ │AND├○● ╰───╯
                    ╰─────┼──▶┤ │ │        
                          │ ╰───╯ │        
            ╭─────────────┼─────────╯        
╭─────╮ │ ╭─────────╮ │                  
│ set ├○╮ ╰▶┤ │ │                  
╰─────╯ │ │[or:_or_]├○╯                  
        ╰────▶┤ │                    
              ╰─────────╯                    
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you stop to analyze, it’s quite simple: following the &lt;code&gt;set&lt;/code&gt; trail, you’ll see there are two logic gates in the path, an &lt;code&gt;OR&lt;/code&gt; and an &lt;code&gt;AND&lt;/code&gt;. One of the &lt;code&gt;OR&lt;/code&gt; gate inputs is connected to the result of the &lt;code&gt;AND&lt;/code&gt; at the end of the chip. This combination makes it so that when we have &lt;strong&gt;0&lt;/strong&gt; and are given a value &lt;strong&gt;1&lt;/strong&gt; , the &lt;code&gt;OR&lt;/code&gt; gate will result in &lt;strong&gt;1&lt;/strong&gt; , and the &lt;code&gt;AND&lt;/code&gt; will also.&lt;/p&gt;

&lt;p&gt;However, when we remove the signal from &lt;code&gt;set&lt;/code&gt;, the value that was previously placed is persisted because now the &lt;code&gt;OR&lt;/code&gt; is maintaining the state that keeps the &lt;code&gt;AND&lt;/code&gt; also in the previous state. Problem solved, right? No! Notice that our circuit is now locked, as there’s no way to get out of this state unless the &lt;code&gt;AND&lt;/code&gt; gets another value, and that’s what the &lt;code&gt;reset&lt;/code&gt; gate is for: it’s connected to a &lt;code&gt;NOT&lt;/code&gt;, meaning while it’s off (0), its result will be 1 (on), and vice versa.&lt;/p&gt;

&lt;p&gt;An evolution we can make to the _ &lt;strong&gt;flip-flop&lt;/strong&gt; _ is to transform it into a _ &lt;strong&gt;Register&lt;/strong&gt; _. In the register, we can choose whether it’s time or not to read our signal and store it, and subsequently rewrite it, all at our leisure. There are many ways to achieve this chip, so I’ll use the implementation demonstrated by &lt;a href="https://www.youtube.com/watch?v=I0-izyq6q5s" rel="noopener noreferrer"&gt;Sebastian Lague&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;In it, we just need to add 3 more logic gates and that’s it!&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Interactive circ widget — &lt;a href="https://jeffersonmourak.com/blog/memory-en/" rel="noopener noreferrer"&gt;view it on the blog&lt;/a&gt;.&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;╭──────╮ ╭───╮ ╭───╮ ╭───╮ ╭───╮ ╭───╮ ╭───╮ ╭───╮ ╭───╮
│ data ├○──●───▶┤ │ ╭─▶┤NOT├○┬──▶┤NOT├○───▶┤ │ ╭──▶┤NOT├○╮ ╭▶┤ │ ╭──▶┤NOT├○●──▶┤LED│
╰──────╯ │ │AND├○─╯ ╰───╯ │ ╰───╯ │AND├○╯ ╰───╯ │ │ │AND├○╯ ╰───╯ │ ╰───╯
           │╭──▶┤ │ │ ╭▶┤ │ ╰─┼▶┤ │ │        
           ││ ╰───╯ │ │ ╰───╯ │ ╰───╯ │        
           ││ ├───────────┼───────────────────╯ │        
╭─────────╮││ ╭───╮ ╭───╮ │ │ │        
│ enabled ├○┼──▶┤NOT├○───▶┤ │ │ ╰─────────────────────────────────────╯        
╰─────────╯ │ ╰───╯ │AND├○╯                                                          
            ╰────────────▶┤ │                                                            
                          ╰───╯                                                            
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If we break it down a bit, what happens is the following: the upper input, which we’ll now call &lt;code&gt;data&lt;/code&gt;, will only be saved in the _ &lt;strong&gt;flip-flop&lt;/strong&gt; _ when the lower input, which also changed names, now called &lt;code&gt;enabled&lt;/code&gt;. So instead of using two inputs, one to save and another to erase, this combination of &lt;code&gt;AND&lt;/code&gt;s and &lt;code&gt;NOT&lt;/code&gt; chooses which operation will be performed.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If &lt;code&gt;data&lt;/code&gt; = 1 and &lt;code&gt;enabled&lt;/code&gt; = 1, then it’s the same as turning on the &lt;code&gt;set&lt;/code&gt; input of the _ &lt;strong&gt;flip-flop&lt;/strong&gt; _.&lt;/li&gt;
&lt;li&gt;If &lt;code&gt;data&lt;/code&gt; = 0 and &lt;code&gt;enabled&lt;/code&gt; = 1, then it’s the same as turning on the &lt;code&gt;reset&lt;/code&gt; input of the _ &lt;strong&gt;flip-flop&lt;/strong&gt; _. Notice that &lt;code&gt;enabled&lt;/code&gt; always needs to be activated so that it can save the signal that was placed in &lt;code&gt;data&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Another thing we can do is take inspiration from the previous article, where at the end we learned that if we combine several Adders, we can do calculations with multiple digits. In memory it’s the same way: combining several registers, you can provide an input for each &lt;code&gt;data&lt;/code&gt; and share the &lt;code&gt;enabled&lt;/code&gt; signal, and thus you can save the values of an entire binary number.&lt;/p&gt;

&lt;p&gt;For now, we say goodbye here, see you next time 😄&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxg2g1p3mcez463cbnc54.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxg2g1p3mcez463cbnc54.gif" alt="Bye bye!"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Bye bye!&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=I0-izyq6q5s" rel="noopener noreferrer"&gt;How Do Computers Remember? (YouTube)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=KM0DdEaY5sY" rel="noopener noreferrer"&gt;SR latch (YouTube)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=peCh_859q7Q" rel="noopener noreferrer"&gt;D latch&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=HjneAhCy2N4" rel="noopener noreferrer"&gt;HOW TRANSISTORS RUN CODE? (YouTube)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.nand2tetris.org/" rel="noopener noreferrer"&gt;From Nand to Tetris&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>cpu</category>
      <category>memory</category>
      <category>combinational</category>
      <category>sequential</category>
    </item>
    <item>
      <title>Prazer, Binário.</title>
      <dc:creator>Jefferson Oliveira</dc:creator>
      <pubDate>Sat, 14 Dec 2024 11:27:04 +0000</pubDate>
      <link>https://dev.to/jeffersonmourak/prazer-binario-bbi</link>
      <guid>https://dev.to/jeffersonmourak/prazer-binario-bbi</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;Olá pessoas dessa internet, para quem está chegando aqui agora, este é o segundo artigo de uma série que estou fazendo para falar sobre os fundamentos da computação, recomendo ler o primeiro sobre &lt;a href="https://jeffersonmourak.com/blog/logic-gates/" rel="noopener noreferrer"&gt;portas lógicas&lt;/a&gt;. E para quem já leu o primeiro artigo, dá um pulinho lá porque eu fiz uma revisão no artigo, recomendo bastante dar uma olhada 😊&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Vamos nos aprofundar um pouco mais e explorar alguns conceitos de matemática e também da história humana.&lt;/p&gt;

&lt;p&gt;A matemática veio da necessidade de contar e medir da raça humana – quantos animais a Maria cuida, quantos dias até o próximo solstício… Com o tempo e a expansão humana, povos antigos criaram vários sistemas de numeração para o seu dia a dia. Jogos como &lt;em&gt;Grand Theft Auto V&lt;/em&gt;, &lt;em&gt;Call of Duty: Black Ops III&lt;/em&gt;, &lt;em&gt;Dragon Quest XI&lt;/em&gt; são exemplos de uso do sistema numeral que os romanos usavam, e o &lt;em&gt;I Ching&lt;/em&gt;, um antigo texto chinês, tem raízes em representações binárias.&lt;/p&gt;

&lt;p&gt;Porém, não somente as antigas civilizações usavam outros sistemas numéricos. As horas de um dia são divididas entre 12 horas do período da manhã e 12 horas do período da tarde, ou uma dúzia de ovos. Na língua francesa ainda existem resquícios de um sistema com base vigesimal (20), por exemplo, o número 80 se diz &lt;em&gt;quatre-vingts&lt;/em&gt; (quatro vintes), e um dos mais recentes é o Braille, que também tem raízes em representações binárias.&lt;/p&gt;

&lt;p&gt;Nos dias atuais, utilizamos a representação decimal, e o motivo é bem simples: a média de dedos em mãos humanas são incríveis 10 dedos, sendo assim fica mais fácil contar usando somente as mãos.&lt;/p&gt;

&lt;h2&gt;
  
  
  ☝️ + ☝️ = ✌️
&lt;/h2&gt;

&lt;p&gt;Essa representação em base 10 é posicional, ou seja, a posição em que os dígitos são “desenhados” muda a quantidade que se está representando. &lt;em&gt;70&lt;/em&gt; representa dez vezes mais que &lt;em&gt;07&lt;/em&gt;, daí vem o ditado popular “zero à esquerda”. Na escola, aprendemos as casas decimais – &lt;em&gt;unidades&lt;/em&gt;, &lt;em&gt;dezenas&lt;/em&gt;, &lt;em&gt;centenas&lt;/em&gt;… Elas servem para representar qual é a posição desse dígito.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Dezena&lt;/th&gt;
&lt;th&gt;Unidade&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;7&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;7&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;E em cima dessa ordem existe uma fórmula matemática que converte um número de qualquer base para decimal. Para facilitar:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Dígito&lt;/strong&gt; : Símbolo que representa uma quantidade única.   &lt;em&gt;Ex.: 1, 2, 3, 4, 5, 6, 7, 8, 9, 0&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Número&lt;/strong&gt; : Dígitos organizados em ordem de _ &lt;strong&gt;posição&lt;/strong&gt; &lt;em&gt;.   _Ex.: 10, 144, 999, 42, 37, &lt;code&gt;0x8A6C&lt;/code&gt;, &lt;code&gt;0b101010&lt;/code&gt;&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Base&lt;/strong&gt; : Quantidade máxima de dígitos que pode ser representada.   &lt;em&gt;Ex.: binário (&lt;code&gt;0b&lt;/code&gt;) 2, decimal 10, hexadecimal (&lt;code&gt;0x&lt;/code&gt;)&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Índice&lt;/strong&gt; : A magnitude do dígito na posição.   _Ex.: 10, o 1 em 10 tem &lt;em&gt;Índice 1&lt;/em&gt; e o 0 tem &lt;em&gt;Índice 0&lt;/em&gt; (é meio contraintuitivo, mas faz sentido).   Em outras palavras, o índice é a posição da direita para a esquerda, começando em 0.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A fórmula é bem simples: &lt;em&gt;&lt;strong&gt;(d)ígito × (b)ase&lt;sup&gt;(i)ndice&lt;/sup&gt;&lt;/strong&gt;&lt;/em&gt;. No exemplo que estamos fazendo, esta é a fórmula para converter 70 em decimal… para 70 em decimal. &lt;strong&gt;7 × 10&lt;sup&gt;1&lt;/sup&gt; + 0 × 10&lt;sup&gt;0&lt;/sup&gt; = 70&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Interactive binary counter widget (base 10, 3 digits) — &lt;a href="https://jeffersonmourak.com/blog/the-binary/" rel="noopener noreferrer"&gt;view it on the blog&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Quando falamos de números dessa forma, fica mais fácil representar o binário, que nada mais é que a quantidade que pode ser representada pela fórmula _ &lt;strong&gt;d × 2&lt;sup&gt;i&lt;/sup&gt;&lt;/strong&gt; _.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Interactive binary counter widget (base 2, 6 digits) — &lt;a href="https://jeffersonmourak.com/blog/the-binary/" rel="noopener noreferrer"&gt;view it on the blog&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;E essa forma de representar quantidades também pode ser manipulada com operações matemáticas. A adição 25 + 17 é resolvida de modo parecido com isso.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1
2 5
1 7
--- +
4 2

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;No exemplo acima, temos alguns elementos que precisam ser destacados:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Um &lt;em&gt;dígito&lt;/em&gt; só pode ser somado com outro &lt;em&gt;dígito&lt;/em&gt; que estiver no mesmo &lt;em&gt;índice&lt;/em&gt;.&lt;/li&gt;
&lt;li&gt;Quando a soma não puder ser representada com apenas um dígito, o menor índice é mantido como &lt;em&gt;resultado&lt;/em&gt;, e o &lt;em&gt;resto&lt;/em&gt; é enviado para o próximo índice.&lt;/li&gt;
&lt;li&gt;O &lt;em&gt;resultado&lt;/em&gt; de uma soma será sempre a soma dos _ &lt;strong&gt;dígitos&lt;/strong&gt; _ do _ &lt;strong&gt;índice&lt;/strong&gt; _ + o _ &lt;strong&gt;resto&lt;/strong&gt; _ que veio do _ &lt;strong&gt;dígito&lt;/strong&gt; _ no _ &lt;strong&gt;índice&lt;/strong&gt; _ anterior.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Com esses mesmos passos, podemos aplicar a soma em qualquer base.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    1 1 1 | 1 |  
1 0 0 0 1 1 | 2 5 | 1 9
0 0 0 1 1 1 | 1 7 | 1 1
------------ + | --- + | --- +
1 0 1 0 1 0 | 4 2 | 2 A 

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7sy4iecq90vos8l5vmx2.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7sy4iecq90vos8l5vmx2.jpeg" alt="Cálculo de 25 + 17 em bases Binária, Decimal e Hexadecimal"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Cálculo de 25 + 17 em bases Binária, Decimal e Hexadecimal&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Interactive binary counter widget (base 2, 6 digits) — &lt;a href="https://jeffersonmourak.com/blog/the-binary/" rel="noopener noreferrer"&gt;view it on the blog&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Agora que já nos conhecemos, como podemos fazer para o computador nos conhecer também?&lt;/p&gt;
&lt;h2&gt;
  
  
  Brincando de tradução
&lt;/h2&gt;

&lt;p&gt;Lembrando do &lt;a href="https://jeffersonmourak.com/blog/logic-gates/" rel="noopener noreferrer"&gt;artigo anterior&lt;/a&gt;, vamos isolar a soma de dois dígitos em tabelas. A primeira, vamos olhar para o resultado apenas. Temos esta tabela que se assemelha muito com a tabela da porta OR, exceto por essa pequena mudança no final.&lt;/p&gt;

&lt;p&gt;| Resultado |&lt;br&gt;
| ? | 0 | 1 |&lt;br&gt;
| 0 | 0 | 1 |&lt;br&gt;
| 1 | 1 | 0 |&lt;/p&gt;

&lt;p&gt;| OR |&lt;br&gt;
| ∨ | 0 | 1 |&lt;br&gt;
| 0 | 0 | 1 |&lt;br&gt;
| 1 | 1 | 1 |&lt;/p&gt;

&lt;p&gt;Para isso, podemos combinar o resultado das portas que já vimos anteriormente em um só circuito chamado “OU Exclusivo” ou “XOR”.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Interactive circ widget — &lt;a href="https://jeffersonmourak.com/blog/the-binary/" rel="noopener noreferrer"&gt;view it on the blog&lt;/a&gt;.&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;╭───╮ ╭─────────────╮ ╭───╮ ╭───╮
│ a ├○●●─▶┤ │╭───▶┤ │ ╭──▶┤LED│
╰───╯ ││ │[nand:_nand_]├○╮ │AND├○╯ ╰───╯
      │●─▶┤ ││╰──▶┤ │          
      ││ ╰─────────────╯│ ╰───╯          
      ││ │                   
╭───╮ ││ ╭─────────╮ │                   
│ b ├○●╰─▶┤ │ │                   
╰───╯ │ │[or:_or_]├○───╯                   
      ╰──▶┤ │                        
          ╰─────────╯                        
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Agora, vamos olhar também para a tabela do resto da nossa soma e se percebe que é uma cópia exata da porta AND.&lt;/p&gt;

&lt;p&gt;| Resto |&lt;br&gt;
| ? | 0 | 1 |&lt;br&gt;
| 0 | 0 | 0 |&lt;br&gt;
| 1 | 0 | 1 |&lt;/p&gt;

&lt;p&gt;| AND |&lt;br&gt;
| ∧ | 0 | 1 |&lt;br&gt;
| 0 | 0 | 0 |&lt;br&gt;
| 1 | 0 | 1 |&lt;/p&gt;

&lt;p&gt;E assim como o Capitão Planeta, “Pela união dos seus poderes”, nós vamos conseguir fazer a operação de soma de dois dígitos em binário, e esse componente é chamado de “Somador” ou “Adder”.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Interactive circ widget — &lt;a href="https://jeffersonmourak.com/blog/the-binary/" rel="noopener noreferrer"&gt;view it on the blog&lt;/a&gt;.&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;╭───╮ ╭───╮ ╭───╮ ╭─────────╮ ╭───╮
│ a ├○●●────▶┤ │ ╭──▶┤ │ ╭────────────▶┤ │ ╭──▶┤LED│
╰───╯ ││ │AND├○╮ │ │AND├○╯ │[or:_or_]├○╯ ╰───╯
      │●────▶┤ │ │ │ ╭▶┤ │ ╭▶┤ │          
      ││ ╰───╯ │ │ │ ╰───╯ │ ╰─────────╯          
      ││ ╰─────────┼─┼───────────────────╯                      
╭───╮ ││ ╭─────────────╮ │ │ ╭─────────────╮ ╭───╮
│ b ├○●╰────▶┤ │ ●─┼▶┤ │ ╭──────────────────▶┤LED│
╰───╯ │ │[xor:_xor_1_]├○● │ │[xor:_xor_2_]├○╯ ╰───╯
      ╰─────▶┤ │ ●▶┤ │                          
             ╰─────────────╯ │ ╰─────────────╯                          
                               │                                          
╭──────╮ │                                          
│ c_in ├○──────────────────────●                                          
╰──────╯                                                                  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Com essa combinação de portas lógicas, um computador já consegue fazer as incríveis somas de: &lt;code&gt;0 + 0&lt;/code&gt;, &lt;code&gt;1 + 0&lt;/code&gt;, &lt;code&gt;0 + 1&lt;/code&gt;, &lt;code&gt;1 + 1&lt;/code&gt;, mas, além disso, ele consegue também dizer quanto que houve de resto da soma. E quando combinados vários ADDERs, a gente consegue fazer uma soma de números mais complexos como o 42, mas essa nós vamos ver no próximo artigo.&lt;/p&gt;

&lt;p&gt;Por hoje é só isso, pessoal.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fy11ml0dh9yuejkbw359t.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fy11ml0dh9yuejkbw359t.gif" alt="Isso é tudo pessoal!"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Isso é tudo pessoal!&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Referências
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://pt.wikipedia.org/wiki/%C3%81lgebra_booliana" rel="noopener noreferrer"&gt;A brief history of numerical systems (Youtube)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://en.wikipedia.org/wiki/Numeral_system" rel="noopener noreferrer"&gt;Numeral system (Wikipédia)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://pt.wikipedia.org/wiki/Sistema_de_numera%C3%A7%C3%A3o" rel="noopener noreferrer"&gt;Sistema de numeração (Wikipédia)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=QZwneRb-zqA" rel="noopener noreferrer"&gt;Exploring How Computers Work (YouTube)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=sTu3LwpF6XI" rel="noopener noreferrer"&gt;Making logic gates from transistors (YouTube)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=HjneAhCy2N4" rel="noopener noreferrer"&gt;HOW TRANSISTORS RUN CODE? (YouTube)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.nand2tetris.org/" rel="noopener noreferrer"&gt;From Nand to Tetris&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>cpu</category>
      <category>binary</category>
      <category>numericsystems</category>
      <category>computação</category>
    </item>
    <item>
      <title>Pleasure to meet you, Binary.</title>
      <dc:creator>Jefferson Oliveira</dc:creator>
      <pubDate>Sat, 14 Dec 2024 10:27:04 +0000</pubDate>
      <link>https://dev.to/jeffersonmourak/pleasure-to-meet-you-binary-4oeb</link>
      <guid>https://dev.to/jeffersonmourak/pleasure-to-meet-you-binary-4oeb</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;Hey Y’all! This is a translation of my blog post originally written in Portuguese.&lt;/p&gt;

&lt;p&gt;Hello people of this internet, for those who are arriving here now, this is the second article of a series I’m doing to talk about the fundamentals of computing, I recommend reading the first one about &lt;a href="https://jeffersonmourak.com/blog/logic-gates/" rel="noopener noreferrer"&gt;logic gates&lt;/a&gt;. And for those who have already read the first article, take a quick look there because I did a revision of the article, I highly recommend taking a look 😊&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Let’s dive a bit deeper and explore some concepts of mathematics and also human history.&lt;/p&gt;

&lt;p&gt;Mathematics came from the human race’s need to count and measure – how many animals Maria takes care of, how many days until the next solstice… Over time and human expansion, ancient peoples created various numbering systems for their daily lives. Games like &lt;em&gt;Grand Theft Auto V&lt;/em&gt;, &lt;em&gt;Call of Duty: Black Ops III&lt;/em&gt;, &lt;em&gt;Dragon Quest XI&lt;/em&gt; are examples of using the numeral system that the Romans used, and the &lt;em&gt;I Ching&lt;/em&gt;, an ancient Chinese text, has roots in binary representations.&lt;/p&gt;

&lt;p&gt;However, not only ancient civilizations used other numerical systems. The hours of a day are divided between 12 hours of the morning period and 12 hours of the afternoon period, or a dozen eggs. In the French language, there are still remnants of a vigesimal-based system (20), for example, the number 80 is said as &lt;em&gt;quatre-vingts&lt;/em&gt; (four twenties), and one of the most recent is Braille, which also has roots in binary representations.&lt;/p&gt;

&lt;p&gt;Nowadays, we use decimal representation, and the reason is quite simple: the average number of fingers on human hands is an incredible 10 fingers, so it’s easier to count using only hands.&lt;/p&gt;

&lt;h2&gt;
  
  
  ☝️ + ☝️ = ✌️
&lt;/h2&gt;

&lt;p&gt;This base 10 representation is positional, meaning the position in which the digits are “drawn” changes the quantity being represented. &lt;em&gt;70&lt;/em&gt; represents ten times more than &lt;em&gt;07&lt;/em&gt;, hence the popular saying “zero to the left”. In school, we learn about decimal places – &lt;em&gt;units&lt;/em&gt;, &lt;em&gt;tens&lt;/em&gt;, &lt;em&gt;hundreds&lt;/em&gt;… They serve to represent what the position of that digit is.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Tens&lt;/th&gt;
&lt;th&gt;Units&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;7&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;7&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;And on top of this order, there’s a mathematical formula that converts a number from any base to decimal. To make it easier:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Digit&lt;/strong&gt; : Symbol that represents a unique quantity.&lt;em&gt;Ex.: 1, 2, 3, 4, 5, 6, 7, 8, 9, 0&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Number&lt;/strong&gt; : Digits organized in order of _ &lt;strong&gt;position&lt;/strong&gt; &lt;em&gt;._Ex.: 10, 144, 999, 42, 37, &lt;code&gt;0x8A6C&lt;/code&gt;, &lt;code&gt;0b101010&lt;/code&gt;&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Base&lt;/strong&gt; : Maximum quantity of digits that can be represented.&lt;em&gt;Ex.: binary (&lt;code&gt;0b&lt;/code&gt;) 2, decimal 10, hexadecimal (&lt;code&gt;0x&lt;/code&gt;)&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Index&lt;/strong&gt; : The magnitude of the digit in the position. _Ex.: 10, the 1 in 10 has &lt;em&gt;Index 1&lt;/em&gt; and the 0 has &lt;em&gt;Index 0&lt;/em&gt; (it’s a bit counterintuitive, but it makes sense). In other words, the index is the position from right to left, starting at 0.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The formula is quite simple: &lt;em&gt;&lt;strong&gt;(d)igit × (b)ase&lt;sup&gt;(i)ndex&lt;/sup&gt;&lt;/strong&gt;&lt;/em&gt;. In the example we’re doing, this is the formula to convert 70 to decimal… to 70 in decimal. &lt;strong&gt;7 × 10&lt;sup&gt;1&lt;/sup&gt; + 0 × 10&lt;sup&gt;0&lt;/sup&gt; = 70&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Interactive binary counter widget (base 10, 3 digits) — &lt;a href="https://jeffersonmourak.com/blog/the-binary-en/" rel="noopener noreferrer"&gt;view it on the blog&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;When we talk about numbers this way, it becomes easier to represent binary, which is nothing more than the quantity that can be represented by the formula _ &lt;strong&gt;d × 2&lt;sup&gt;i&lt;/sup&gt;&lt;/strong&gt; _.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Interactive binary counter widget (base 2, 6 digits) — &lt;a href="https://jeffersonmourak.com/blog/the-binary-en/" rel="noopener noreferrer"&gt;view it on the blog&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;And this way of representing quantities can also be manipulated with mathematical operations. The addition 25 + 17 is solved in a way similar to this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1
2 5
1 7
--- +
4 2

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the example above, we have some elements that need to be highlighted:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;A &lt;em&gt;digit&lt;/em&gt; can only be added to another &lt;em&gt;digit&lt;/em&gt; that is in the same &lt;em&gt;index&lt;/em&gt;.&lt;/li&gt;
&lt;li&gt;When the sum cannot be represented with just one digit, the smallest index is kept as the &lt;em&gt;result&lt;/em&gt;, and the &lt;em&gt;remainder&lt;/em&gt; is sent to the next index.&lt;/li&gt;
&lt;li&gt;The &lt;em&gt;result&lt;/em&gt; of a sum will always be the sum of the _ &lt;strong&gt;digits&lt;/strong&gt; _ of the _ &lt;strong&gt;index&lt;/strong&gt; _ + the _ &lt;strong&gt;remainder&lt;/strong&gt; _ that came from the _ &lt;strong&gt;digit&lt;/strong&gt; _ in the previous _ &lt;strong&gt;index&lt;/strong&gt; _.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;With these same steps, we can apply addition in any base.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    1 1 1 | 1 |  
1 0 0 0 1 1 | 2 5 | 1 9
0 0 0 1 1 1 | 1 7 | 1 1
------------ + | --- + | --- +
1 0 1 0 1 0 | 4 2 | 2 A 

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhxd8jf9pegv4wvkw8od6.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhxd8jf9pegv4wvkw8od6.jpeg" alt="Calculation of 25 + 17 in Binary, Decimal and Hexadecimal bases"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Calculation of 25 + 17 in Binary, Decimal and Hexadecimal bases&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Interactive binary counter widget (base 2, 6 digits) — &lt;a href="https://jeffersonmourak.com/blog/the-binary-en/" rel="noopener noreferrer"&gt;view it on the blog&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Now that we already know each other, how can we make the computer know us too?&lt;/p&gt;
&lt;h2&gt;
  
  
  Playing with translation
&lt;/h2&gt;

&lt;p&gt;Remembering the &lt;a href="https://jeffersonmourak.com/blog/logic-gates/" rel="noopener noreferrer"&gt;previous article&lt;/a&gt;, let’s isolate the addition of two digits in tables. First, let’s look at just the result. We have this table that very much resembles the OR gate table, except for this small change at the end.&lt;/p&gt;

&lt;p&gt;| Result |&lt;br&gt;
| ? | 0 | 1 |&lt;br&gt;
| 0 | 0 | 1 |&lt;br&gt;
| 1 | 1 | 0 |&lt;/p&gt;

&lt;p&gt;| OR |&lt;br&gt;
| ∨ | 0 | 1 |&lt;br&gt;
| 0 | 0 | 1 |&lt;br&gt;
| 1 | 1 | 1 |&lt;/p&gt;

&lt;p&gt;For this, we can combine the results of the gates we saw earlier into a single circuit called “Exclusive OR” or “XOR”.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Interactive circ widget — &lt;a href="https://jeffersonmourak.com/blog/the-binary-en/" rel="noopener noreferrer"&gt;view it on the blog&lt;/a&gt;.&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;╭───╮ ╭─────────────╮ ╭───╮ ╭───╮
│ a ├○●●─▶┤ │╭───▶┤ │ ╭──▶┤LED│
╰───╯ ││ │[nand:_nand_]├○╮ │AND├○╯ ╰───╯
      │●─▶┤ ││╰──▶┤ │          
      ││ ╰─────────────╯│ ╰───╯          
      ││ │                   
╭───╮ ││ ╭─────────╮ │                   
│ b ├○●╰─▶┤ │ │                   
╰───╯ │ │[or:_or_]├○───╯                   
      ╰──▶┤ │                        
          ╰─────────╯                        
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, let’s also look at the remainder table of our addition and you’ll notice that it’s an exact copy of the AND gate.&lt;/p&gt;

&lt;p&gt;| Remainder |&lt;br&gt;
| ? | 0 | 1 |&lt;br&gt;
| 0 | 0 | 0 |&lt;br&gt;
| 1 | 0 | 1 |&lt;/p&gt;

&lt;p&gt;| AND |&lt;br&gt;
| ∧ | 0 | 1 |&lt;br&gt;
| 0 | 0 | 0 |&lt;br&gt;
| 1 | 0 | 1 |&lt;/p&gt;

&lt;p&gt;And just like Captain Planet, “By the union of their powers”, we will be able to perform the operation of adding two digits in binary, and this component is called “Adder”.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Interactive circ widget — &lt;a href="https://jeffersonmourak.com/blog/the-binary-en/" rel="noopener noreferrer"&gt;view it on the blog&lt;/a&gt;.&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;╭───╮ ╭───╮ ╭───╮ ╭─────────╮ ╭───╮
│ a ├○●●────▶┤ │ ╭──▶┤ │ ╭────────────▶┤ │ ╭──▶┤LED│
╰───╯ ││ │AND├○╮ │ │AND├○╯ │[or:_or_]├○╯ ╰───╯
      │●────▶┤ │ │ │ ╭▶┤ │ ╭▶┤ │          
      ││ ╰───╯ │ │ │ ╰───╯ │ ╰─────────╯          
      ││ ╰─────────┼─┼───────────────────╯                      
╭───╮ ││ ╭─────────────╮ │ │ ╭─────────────╮ ╭───╮
│ b ├○●╰────▶┤ │ ●─┼▶┤ │ ╭──────────────────▶┤LED│
╰───╯ │ │[xor:_xor_1_]├○● │ │[xor:_xor_2_]├○╯ ╰───╯
      ╰─────▶┤ │ ●▶┤ │                          
             ╰─────────────╯ │ ╰─────────────╯                          
                               │                                          
╭──────╮ │                                          
│ c_in ├○──────────────────────●                                          
╰──────╯                                                                  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With this combination of logic gates, a computer can already perform the incredible additions of: &lt;code&gt;0 + 0&lt;/code&gt;, &lt;code&gt;1 + 0&lt;/code&gt;, &lt;code&gt;0 + 1&lt;/code&gt;, &lt;code&gt;1 + 1&lt;/code&gt;, but beyond that, it can also say how much remainder there was from the addition. And when several ADDERs are combined, we can perform addition of more complex numbers like 42, but that we’ll see in the next article.&lt;/p&gt;

&lt;p&gt;That’s all for today, folks. &lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fy11ml0dh9yuejkbw359t.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fy11ml0dh9yuejkbw359t.gif" alt="That’s all folks!"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://pt.wikipedia.org/wiki/%C3%81lgebra_booliana" rel="noopener noreferrer"&gt;A brief history of numerical systems (Youtube)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://en.wikipedia.org/wiki/Numeral_system" rel="noopener noreferrer"&gt;Numeral system (Wikipédia)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://pt.wikipedia.org/wiki/Sistema_de_numera%C3%A7%C3%A3o" rel="noopener noreferrer"&gt;Sistema de numeração (Wikipédia)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=QZwneRb-zqA" rel="noopener noreferrer"&gt;Exploring How Computers Work (YouTube)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=sTu3LwpF6XI" rel="noopener noreferrer"&gt;Making logic gates from transistors (YouTube)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=HjneAhCy2N4" rel="noopener noreferrer"&gt;HOW TRANSISTORS RUN CODE? (YouTube)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.nand2tetris.org/" rel="noopener noreferrer"&gt;From Nand to Tetris&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>cpu</category>
      <category>binary</category>
      <category>numericsystems</category>
      <category>computing</category>
    </item>
    <item>
      <title>Portas lógicas</title>
      <dc:creator>Jefferson Oliveira</dc:creator>
      <pubDate>Thu, 07 Nov 2024 11:27:04 +0000</pubDate>
      <link>https://dev.to/jeffersonmourak/portas-logicas-3ia7</link>
      <guid>https://dev.to/jeffersonmourak/portas-logicas-3ia7</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;Revisado [11/12/2024]&lt;/p&gt;

&lt;p&gt;Oi pessoal, então tive que fazer umas mudanças aqui no post pra adicionar alguns widgets interativos, e aproveitei para dar um pouco mais de contexto ao conteúdo.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Olá, este é o primeiro artigo de uma série sobre os fundamentos da computação. A ideia é demonstrar de forma simples e prática como este dispositivo transforma zeros e uns em praticamente qualquer coisa, o funcionamento das CPUs e outros assuntos interessantes. Então, para começar, o primeiro conceito que temos que aprender é o de portas lógicas: elas são a base de toda a computação, com elas podemos fazer certas operações que recebem como entrada um ou mais valores e terão outro valor como resultado.&lt;/p&gt;

&lt;p&gt;Mas o que são esses valores? O número 42? O nome da minha mãe? Esses “valores” são energia, mais especificamente a presença e ausência dela. Como foi falado na introdução, computadores funcionam utilizando dígitos binários, ou seja, essas máquinas só entendem 0 e 1 ou “Tem energia” e “Não tem energia”. No entanto, não iremos chamar esses zeros e uns de energia, para o computador eles são sinais.&lt;/p&gt;

&lt;p&gt;Quando sinais são combinados e/ou comparados, nós chamamos de operação lógica, por exemplo.&lt;/p&gt;

&lt;p&gt;“[Sons de harpa de inicio de história]”&lt;/p&gt;

&lt;p&gt;Um dia você contrata uma empresa de elétrica para instalar dois interruptores em um corredor da sua casa, mas, por um erro de desenho, a instalação acaba ficando da seguinte forma: o fio passa pelo primeiro interruptor (vamos chamar de interruptor A), vai direto para o segundo interruptor (B para os íntimos) e, em seguida, sai para a lâmpada.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fesa4dayjxkq20o851gsz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fesa4dayjxkq20o851gsz.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Reparou que a lâmpada só acende se os dois interruptores estiverem ligados ao mesmo tempo? Se qualquer um deles for desligado, a luz apaga na hora! Pois é, essa atrocidade da elétrica residencial pode ser explicada, na matemática, a partir de um de seus ramos chamado de álgebra booleana, e nela podemos demonstrar isso com uma tabela:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;∧&lt;/th&gt;
&lt;th&gt;0&lt;/th&gt;
&lt;th&gt;1&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Escrevendo isso de outro modo fica assim:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;∧&lt;/th&gt;
&lt;th&gt;A desligado&lt;/th&gt;
&lt;th&gt;A ligado&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;B desligado&lt;/td&gt;
&lt;td&gt;Luz apagada&lt;/td&gt;
&lt;td&gt;Luz apagada&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;B ligado&lt;/td&gt;
&lt;td&gt;Luz apagada&lt;/td&gt;
&lt;td&gt;Luz acesa&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Se você percebeu bem, agora temos um jeito de representar o que queremos que aconteça com dois interruptores e uma lâmpada, e esse exemplo mostrado acima é a primeira porta lógica que estamos conhecendo, o AND ou Conjunção, e essa tabela, demonstrada acima de formas diferentes, se chama Tabela-Verdade.&lt;/p&gt;

&lt;p&gt;Ok, mas e a luz da minha casa? Como que vai ficar? Eu preciso que a luz acenda quando o A OU B estiverem ligados. Como que faz isso?&lt;/p&gt;

&lt;p&gt;A resposta está na própria pergunta! 😉 Vamos precisar de uma outra porta lógica, a OR ou Disjunção, e para entender como ela funciona, vamos usar uma tabela-verdade que se encaixe nessas condições:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;?&lt;/th&gt;
&lt;th&gt;0&lt;/th&gt;
&lt;th&gt;1&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Mas antes de falar da OR, vamos dar uma olhada na porta NOT (ou Negação). Ela é bem simples, mas vai ser importante mais pra frente.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Interactive circ widget — &lt;a href="https://jeffersonmourak.com/blog/logic-gates/" rel="noopener noreferrer"&gt;view it on the blog&lt;/a&gt;.&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;╭───╮ ╭───╮ ╭───╮
│ a ├○───▶┤NOT├○───▶┤LED│
╰───╯ ╰───╯ ╰───╯
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;E se escrevermos ela numa tabela verdade teremos isso aqui:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;¬&lt;/th&gt;
&lt;th&gt;0&lt;/th&gt;
&lt;th&gt;1&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Então, vamos fazer uma pausa e revisar o que a gente já sabe. Primeiro, as operações e como representá-las numa tabela. Para simplificar, vamos transformar essas operações em símbolos. Toda vez que nos referirmos ao AND, este será o símbolo:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Interactive circ widget — &lt;a href="https://jeffersonmourak.com/blog/logic-gates/" rel="noopener noreferrer"&gt;view it on the blog&lt;/a&gt;.&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;╭───╮ ╭───╮ ╭───╮
│ a ├○───▶┤ │ ╭──▶┤LED│
╰───╯ │AND├○╯ ╰───╯
       ╭─▶┤ │          
       │ ╰───╯          
       │                 
╭───╮ │                 
│ b ├○─╯                 
╰───╯                    
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;e o NOT:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Interactive circ widget — &lt;a href="https://jeffersonmourak.com/blog/logic-gates/" rel="noopener noreferrer"&gt;view it on the blog&lt;/a&gt;.&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;╭───╮ ╭───╮ ╭───╮
│ a ├○───▶┤NOT├○───▶┤LED│
╰───╯ ╰───╯ ╰───╯
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Com essas duas operações lógicas (AND e NOT), já podemos combinar seus resultados e criar uma terceira porta lógica: a NAND (ou Not AND).&lt;/p&gt;

&lt;p&gt;Ela pode ser representada assim:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Interactive circ widget — &lt;a href="https://jeffersonmourak.com/blog/logic-gates/" rel="noopener noreferrer"&gt;view it on the blog&lt;/a&gt;.&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;╭───╮ ╭─────────────╮ ╭───╮
│ a ├○───▶┤ │ ╭──▶┤LED│
╰───╯ │[nand:_nand_]├○╯ ╰───╯
       ╭─▶┤ │          
       │ ╰─────────────╯          
       │                           
╭───╮ │                           
│ b ├○─╯                           
╰───╯                              
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Interactive circ widget — &lt;a href="https://jeffersonmourak.com/blog/logic-gates/" rel="noopener noreferrer"&gt;view it on the blog&lt;/a&gt;.&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;╭───╮ ╭───╮ ╭───╮ ╭───╮
│ a ├○───▶┤ │ ╭──▶┤NOT├○───▶┤LED│
╰───╯ │AND├○╯ ╰───╯ ╰───╯
       ╭─▶┤ │                    
       │ ╰───╯                    
       │                           
╭───╮ │                           
│ b ├○─╯                           
╰───╯                              
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A tabela-verdade dela é idêntica à do AND, porém com os resultados invertidos.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;¬∧&lt;/th&gt;
&lt;th&gt;0&lt;/th&gt;
&lt;th&gt;1&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Seguindo essa mesma lógica de combinar portas, podemos usar uma porta NAND e inverter a entrada de cada interruptor com um NOT. Assim, teremos o seguinte:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Interactive circ widget — &lt;a href="https://jeffersonmourak.com/blog/logic-gates/" rel="noopener noreferrer"&gt;view it on the blog&lt;/a&gt;.&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;╭───╮ ╭───╮ ╭─────────────╮ ╭───╮
│ a ├○───▶┤NOT├○───▶┤ │ ╭──▶┤LED│
╰───╯ ╰───╯ │[nand:_nand_]├○╯ ╰───╯
                 ╭─▶┤ │          
                 │ ╰─────────────╯          
                 │                           
╭───╮ ╭───╮ │                           
│ b ├○───▶┤NOT├○─╯                           
╰───╯ ╰───╯                              
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Analisando o diagrama acima, vemos que, quando os dois interruptores estiverem desligados, ambos os sinais serão invertidos pelo NOT, e o NAND vai resultar em ¬∧(1, 1) = 0. Ou seja, com ambos desligados, a lâmpada apaga. Mas o que acontece quando temos ¬∧(1, 0) ou ¬∧(0, 1)? Para descobrir, vamos analisar a tabela-verdade:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;∨&lt;/th&gt;
&lt;th&gt;0&lt;/th&gt;
&lt;th&gt;1&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6wmlfuc6zwizb0l5sbev.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6wmlfuc6zwizb0l5sbev.gif" alt="Eu acho que vi um gatinho!"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Eu acho que vi um gatinho!&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Mas espera um pouco, eu tenho a impressão de que eu já vi essa tabela antes? Sim! Essa é a porta lógica OR que estávamos procurando. Uma viagem e tanto, não é? Agora que já sabemos como consertar a fiação da lâmpada, podemos dar uma paradinha aqui. Este é apenas o primeiro artigo de uma série sobre computadores. Mais para frente, vamos abordar outras portas lógicas e outros conceitos da computação.&lt;/p&gt;

&lt;h2&gt;
  
  
  Referências
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://pt.wikipedia.org/wiki/%C3%81lgebra_booliana" rel="noopener noreferrer"&gt;Álgebra booliana (Wikipédia)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://en.wikipedia.org/wiki/Boolean_algebra" rel="noopener noreferrer"&gt;Boolean Algebra (Wikipédia)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://pt.wikipedia.org/wiki/Tabela-verdade" rel="noopener noreferrer"&gt;Tabela-verdade (Wikipédia)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=QZwneRb-zqA" rel="noopener noreferrer"&gt;Exploring How Computers Work (YouTube)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=sTu3LwpF6XI" rel="noopener noreferrer"&gt;Making logic gates from transistors (YouTube)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=HjneAhCy2N4" rel="noopener noreferrer"&gt;HOW TRANSISTORS RUN CODE? (YouTube)&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>cpu</category>
      <category>logicgates</category>
      <category>portaslógicas</category>
      <category>computação</category>
    </item>
  </channel>
</rss>
