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

<channel>
	<title>bitwise operators Archives - SoftUni Global</title>
	<atom:link href="https://softuni.org/tag/bitwise-operators/feed/" rel="self" type="application/rss+xml" />
	<link>https://softuni.org/tag/bitwise-operators/</link>
	<description>Learn Programming and Start a Developer Job</description>
	<lastBuildDate>Thu, 28 Apr 2022 11:27:11 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://softuni.org/wp-content/uploads/2022/04/cropped-SoftUni-Global-Logo-Square-notext-32x32.png</url>
	<title>bitwise operators Archives - SoftUni Global</title>
	<link>https://softuni.org/tag/bitwise-operators/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Bitwise Operations in Programming [Dev Concepts #34]</title>
		<link>https://softuni.org/dev-concepts/bitwise-operations-in-programming/</link>
					<comments>https://softuni.org/dev-concepts/bitwise-operations-in-programming/#respond</comments>
		
		<dc:creator><![CDATA[Aleksandar Peev]]></dc:creator>
		<pubDate>Wed, 27 Apr 2022 06:00:00 +0000</pubDate>
				<category><![CDATA[Dev Concepts]]></category>
		<category><![CDATA[binary]]></category>
		<category><![CDATA[bit-level]]></category>
		<category><![CDATA[bitmasks]]></category>
		<category><![CDATA[bitwise operations]]></category>
		<category><![CDATA[bitwise operators]]></category>
		<category><![CDATA[devconcepts]]></category>
		<category><![CDATA[mathematics]]></category>
		<category><![CDATA[maths]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[software engineering]]></category>
		<guid isPermaLink="false">https://softuni.org/?p=18889</guid>

					<description><![CDATA[<p>In this lesson you will get an idea of bitwise operations: how they work and why we need them in computer programming. We will explain and demonstrate the main bitwise operators and introduce the concept of bitmasks.</p>
<p>The post <a href="https://softuni.org/dev-concepts/bitwise-operations-in-programming/">Bitwise Operations in Programming [Dev Concepts #34]</a> appeared first on <a href="https://softuni.org">SoftUni Global</a>.</p>
]]></description>
										<content:encoded><![CDATA[		<div data-elementor-type="wp-post" data-elementor-id="18889" class="elementor elementor-18889" data-elementor-post-type="post">
						<section class="elementor-section elementor-top-section elementor-element elementor-element-5d5405e elementor-section-boxed elementor-section-height-default elementor-section-height-default" data-id="5d5405e" data-element_type="section">
						<div class="elementor-container elementor-column-gap-default">
					<div class="elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-0d32134" data-id="0d32134" data-element_type="column">
			<div class="elementor-widget-wrap elementor-element-populated">
						<div class="elementor-element elementor-element-9216798 elementor-widget elementor-widget-text-editor" data-id="9216798" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
									<p><span data-preserver-spaces="true">In this article, we will also solve several <strong>practical problems</strong> using bitwise operations:<br /></span></p><ul><li><span data-preserver-spaces="true">Get the </span><strong><span data-preserver-spaces="true">last bit </span></strong><span data-preserver-spaces="true">from an integer</span></li><li>Get the <strong style="font-size: 16px;"><span data-preserver-spaces="true">bit at a certain index</span></strong><span style="font-size: 16px;" data-preserver-spaces="true"> from an integer</span></li><li>Change the <strong style="font-size: 16px;"><span data-preserver-spaces="true">bit at a certain index</span></strong><span style="font-size: 16px;" data-preserver-spaces="true"> in an integer</span></li><li>Extract the <strong>bit before the last</strong> from an integer</li></ul><p>If you are not familiar with <strong>bits</strong> and <strong>storing data on the computer</strong> you can read our previous articles about them here:</p><ul><li><a href="https://softuni.org/dev-concepts/what-you-need-to-know-about-bits-bytes-and-kilobytes/">What You Need to Know About Bits, Bytes, and Kilobytes [Dev Concepts #31]</a></li><li><a href="https://softuni.org/dev-concepts/data-representation-in-computer-memory/">Data Representation in Computer Memory [Dev Concepts #33]</a></li></ul>								</div>
				</div>
				<div class="elementor-element elementor-element-88292b4 elementor-widget elementor-widget-video" data-id="88292b4" data-element_type="widget" data-settings="{&quot;youtube_url&quot;:&quot;https:\/\/www.youtube.com\/watch?v=H9U4ylrFVec&quot;,&quot;video_type&quot;:&quot;youtube&quot;,&quot;controls&quot;:&quot;yes&quot;}" data-widget_type="video.default">
				<div class="elementor-widget-container">
							<div class="elementor-wrapper elementor-open-inline">
			<div class="elementor-video"></div>		</div>
						</div>
				</div>
				<div class="elementor-element elementor-element-3d7dddf elementor-widget elementor-widget-text-editor" data-id="3d7dddf" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
									<h3 style="text-align: center;">Bitwise Operations</h3><p>First, let&#8217;s start with learning about the bitwise operations in programming. They work with the <strong>binary representations</strong> of the numbers, applying <strong><span data-preserver-spaces="true">bit-by-bit</span></strong><strong> calculations</strong>. For example, if we have two <strong>8-bit numbers</strong>, we can apply a bitwise operation, which takes as input the first <strong>8 bits</strong> and the second <strong>8 bits</strong> and produces as a result new <strong>8 bits</strong>.</p>								</div>
				</div>
				<div class="elementor-element elementor-element-6a72260 elementor-widget elementor-widget-text-editor" data-id="6a72260" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
									<p>A simple bitwise operator over a single argument is the &#8220;<strong>tilde</strong>&#8221; operator – the bitwise logical NOT (also called negation). The operator &#8220;<strong>tilde</strong>&#8221; turns all zeroes to ones and all ones to zeroes, like the &#8220;<strong>exclamation mark</strong>&#8221; operator for the <strong>Boolean expressions</strong>, but it works bit by bit. For example, if we have the <strong>binary number</strong> &#8220;<strong>1 0 0&#8243;</strong>, its negation &#8220;<strong>tilde 1 0 0</strong>&#8221; is &#8220;<strong>0 1 1</strong>&#8220;.</p>								</div>
				</div>
				<div class="elementor-element elementor-element-1a7d81a elementor-widget elementor-widget-image" data-id="1a7d81a" data-element_type="widget" data-widget_type="image.default">
				<div class="elementor-widget-container">
															<img decoding="async" src="https://softuni.org/wp-content/uploads/elementor/thumbs/table-pnol310ovy736u0r6p3vjqkq4wh1e281yd2ynee2hi.png" title="OperatorTable" alt="OperatorTable" loading="lazy" />															</div>
				</div>
				<div class="elementor-element elementor-element-fed9f83 elementor-widget elementor-widget-text-editor" data-id="fed9f83" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
									<p>The table above illustrates the work of the bitwise <strong>OR</strong>, <strong>AND,</strong> and <strong>XOR</strong> operators.</p><ul><li><span data-preserver-spaces="true">The </span><strong><span data-preserver-spaces="true">bitwise OR operator</span></strong><span data-preserver-spaces="true"> (denoted by the </span><strong><span data-preserver-spaces="true">vertical bar </span></strong><span data-preserver-spaces="true">in most programming languages) returns 1, if </span><strong><span data-preserver-spaces="true">one of its input bits is 1</span></strong><span data-preserver-spaces="true">, otherwise returns 0.</span></li><li><span data-preserver-spaces="true">The </span><strong><span data-preserver-spaces="true">bitwise AND operator</span></strong><span data-preserver-spaces="true"> (denoted by the </span><strong><span data-preserver-spaces="true">ampersand</span></strong><span data-preserver-spaces="true"> in most programming languages) returns 1, if </span><strong><span data-preserver-spaces="true">both of its input bits are 1</span></strong><span data-preserver-spaces="true">, otherwise returns 0.</span></li><li>The <strong style="font-size: 16px;"><span data-preserver-spaces="true">bitwise exclusive OR (XOR) operator</span></strong><span style="font-size: 16px;" data-preserver-spaces="true"> (denoted by the </span><strong style="font-size: 16px;"><span data-preserver-spaces="true">ampersand</span></strong><span style="font-size: 16px;" data-preserver-spaces="true"> in most programming languages) returns 1 if </span><strong style="font-size: 16px;"><span data-preserver-spaces="true">one of its arguments is 1, but not both </span></strong><span style="font-size: 16px;" data-preserver-spaces="true">at the same time, otherwise returns 0.</span></li></ul>								</div>
				</div>
				<div class="elementor-element elementor-element-e92b10b elementor-widget elementor-widget-text-editor" data-id="e92b10b" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
									<h3 style="text-align: center;">Bit Shifts</h3><p><strong><span data-preserver-spaces="true">Bit shifts</span></strong><span data-preserver-spaces="true"> are bitwise operations, where </span><strong><span data-preserver-spaces="true">bits inside </span></strong><span data-preserver-spaces="true">a number are moved (or shifted) to the left or the right. </span><span data-preserver-spaces="true">During the shifting operation, the bits that fall at invalid positions are lost, and the bits which come from missing positions are </span><strong><span data-preserver-spaces="true">replaced by 0.</span></strong></p>								</div>
				</div>
				<div class="elementor-element elementor-element-4b232c0 elementor-widget elementor-widget-image" data-id="4b232c0" data-element_type="widget" data-widget_type="image.default">
				<div class="elementor-widget-container">
															<img decoding="async" src="https://softuni.org/wp-content/uploads/elementor/thumbs/left-and-right-shift-pnold3ue5zzrobdqc1xva70nfmspx88g08wdw7g3qc.png" title="left-and-right-shift" alt="left-and-right-shift" loading="lazy" />															</div>
				</div>
				<div class="elementor-element elementor-element-f3357d7 elementor-widget elementor-widget-text-editor" data-id="f3357d7" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
									<p><strong>Bit shifting</strong> can be applied for <b>8-bit</b>, <b>16-bit</b>, <b>32-bit, </b>and <b>64-bit</b> numbers, as well as for numbers of other sizes in bits. The <b>bit size </b>of the number being shifted defines the <b>valid bit positions </b>and where the bits get lost. <strong>Bits</strong> can be shifted by more than<strong> 1</strong> position. For example, <strong>5</strong> shifted left twice is <strong>20</strong> and<strong> 5</strong> shifted right twice is <strong>1</strong>.</p>								</div>
				</div>
				<div class="elementor-element elementor-element-2a0da3f elementor-drop-cap-yes elementor-drop-cap-view-default elementor-widget elementor-widget-text-editor" data-id="2a0da3f" data-element_type="widget" data-settings="{&quot;drop_cap&quot;:&quot;yes&quot;}" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
									<h3 style="text-align: center;">Why We Need Bitwise Operations?​</h3><p><strong><span data-preserver-spaces="true">Processing bits </span></strong><span data-preserver-spaces="true">is <span style="color: #000000;">important</span> for many fields of computer science, information technologies, and software systems, like </span><strong><span data-preserver-spaces="true">networking protocols</span></strong><span data-preserver-spaces="true">, data storage, and file systems, binary file </span><strong><span data-preserver-spaces="true">formats</span></strong><span data-preserver-spaces="true">, </span><strong><span data-preserver-spaces="true">memory management</span></strong><span data-preserver-spaces="true">, data compression, data encryption, video streaming, Internet of things (IoT) systems, </span><strong><span data-preserver-spaces="true">low-level programming</span></strong><span data-preserver-spaces="true">, computer graphics, and many others.</span></p>								</div>
				</div>
				<div class="elementor-element elementor-element-7b9e6ca elementor-widget elementor-widget-image" data-id="7b9e6ca" data-element_type="widget" data-widget_type="image.default">
				<div class="elementor-widget-container">
															<img decoding="async" src="https://softuni.org/wp-content/uploads/elementor/thumbs/Binary-and-Text-File-pnomvd31vl1gzfdzlcfbsh4uht4vm4v7f3mp9my9ue.png" title="Binary-and-Text-File" alt="Binary-and-Text-File" loading="lazy" />															</div>
				</div>
				<div class="elementor-element elementor-element-b60470c elementor-widget elementor-widget-text-editor" data-id="b60470c" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
									<p><span data-preserver-spaces="true"><strong>D</strong><b>ata compression </b></span><span data-preserver-spaces="true">algorithms replace bit or byte sequences with shorter bit sequences. For example, the &#8220;<strong>DEFLATE</strong>&#8221; <strong>algorithm</strong>, used to compress data in the </span><strong><span data-preserver-spaces="true">ZIP files</span></strong><span data-preserver-spaces="true">, finds the most often sequences and replaces them with shorter sequences, while it preserves a dictionary between the original bit sequences and their shorter compressed form. This is done using </span><strong><span data-preserver-spaces="true">heavy bit-level</span></strong><span data-preserver-spaces="true"> processing with bitwise operations.</span></p>								</div>
				</div>
				<div class="elementor-element elementor-element-edfdd22 elementor-widget elementor-widget-text-editor" data-id="edfdd22" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
									<p><span data-preserver-spaces="true">Many <strong>binary file formats</strong> use bits to save space. For example, </span><strong><span data-preserver-spaces="true">PNG</span></strong><span data-preserver-spaces="true"> images (the Portable Network Graphics image format) use <strong>3 bits</strong> to specify the color format used (<strong>8-bit</strong> color, <strong>24-bit</strong> color, <strong>32-bit</strong> color with transparency). These <strong>3 bits</strong> are located at a certain offset in the <strong>PNG image header bytes</strong>, so reading and writing the value encoded in these <strong>3 bits</strong> require bitwise operations.</span></p>								</div>
				</div>
				<div class="elementor-element elementor-element-519abd5 elementor-widget elementor-widget-text-editor" data-id="519abd5" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
									<p>To sum it up, bitwise operators work with the <strong>binary representations</strong> of the <strong>numbers</strong>, applying<strong> bit-by-bit calculations</strong>. <strong>Bit shifts</strong> are bitwise operations, where bits inside a number are <strong>shifted</strong> to the left or the right. These concepts are an <strong>important aspect of many fields of computer science</strong>.</p>								</div>
				</div>
				<div class="elementor-element elementor-element-4a0f072 elementor-widget elementor-widget-text-editor" data-id="4a0f072" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
									<h2>Lesson Topics</h2><div><div><div>In this tutorial, we cover the following topics:</div></div><ul><li><p><strong>Bitwise Operations</strong></p></li><li><p><strong>Bitwise Operators &#8211; Examples</strong></p></li><li><p><strong>Bit Shifts</strong></p></li><li><p><strong>Bitwise Operations Problems</strong></p></li><li><p><strong>Why We Need Bitwise Operations?</strong></p></li><li><p><strong>Bit Before the Last &#8211; Problems</strong></p></li></ul></div>								</div>
				</div>
					</div>
		</div>
					</div>
		</section>
				<section class="elementor-section elementor-top-section elementor-element elementor-element-3381a86 elementor-section-boxed elementor-section-height-default elementor-section-height-default" data-id="3381a86" data-element_type="section">
						<div class="elementor-container elementor-column-gap-default">
					<div class="elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-0cf09e3" data-id="0cf09e3" data-element_type="column">
			<div class="elementor-widget-wrap elementor-element-populated">
							</div>
		</div>
					</div>
		</section>
				<section class="elementor-section elementor-top-section elementor-element elementor-element-a0aff0b elementor-section-boxed elementor-section-height-default elementor-section-height-default" data-id="a0aff0b" data-element_type="section">
						<div class="elementor-container elementor-column-gap-default">
					<div class="elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-48c6c18" data-id="48c6c18" data-element_type="column">
			<div class="elementor-widget-wrap elementor-element-populated">
						<div class="elementor-element elementor-element-f972417 elementor-widget elementor-widget-heading" data-id="f972417" data-element_type="widget" data-widget_type="heading.default">
				<div class="elementor-widget-container">
					<h2 class="elementor-heading-title elementor-size-default">Lesson Slides</h2>				</div>
				</div>
				<div class="elementor-element elementor-element-37e6760 elementor-widget elementor-widget-pdfjs_viewer" data-id="37e6760" data-element_type="widget" data-widget_type="pdfjs_viewer.default">
				<div class="elementor-widget-container">
					<iframe src="https://softuni.org/wp-content/plugins/pdf-viewer-for-elementor/assets/pdfjs/web/viewer.html?file=https://softuni.org/wp-content/uploads/2022/04/Dev-Concepts-Episode-34-Bitwise-Operations-in-Programming.pdf&amp;embedded=true" style="display: block; margin-left: auto; margin-right: auto; width: 100%; height: 800px;" frameborder="1" marginheight="0px" marginwidth="0px" allowfullscreen></iframe>				</div>
				</div>
					</div>
		</div>
					</div>
		</section>
				</div>
		<p>The post <a href="https://softuni.org/dev-concepts/bitwise-operations-in-programming/">Bitwise Operations in Programming [Dev Concepts #34]</a> appeared first on <a href="https://softuni.org">SoftUni Global</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://softuni.org/dev-concepts/bitwise-operations-in-programming/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>

<!--
Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/?utm_source=w3tc&utm_medium=footer_comment&utm_campaign=free_plugin

Page Caching using Disk: Enhanced 
Lazy Loading (feed)

Served from: softuni.org @ 2026-06-19 04:33:50 by W3 Total Cache
-->