Convert Binary, Octal, Decimal, and Hexadecimal in Python

Understanding Number Systems In Python, there are four commonly used number systems: binary, octal, decimal, and hexadecimal. Each system represents numbers using a different base or radix. Binary (base 2) uses only two digits, 0 and 1, to represent numbers. For example, the binary representation of the decimal number 5 is 101. Octal (base 8) … Read more

How Exactly Does Ledger Generate the 24 Random Words? Risks Inside

Ledger hardware wallets are a go-to choice for many crypto enthusiasts looking to store their digital assets securely. Their technology revolves around the generation of a 24-word recovery phrase, a critical component in the security of the wallet. Let’s dive into the inner workings of Ledger’s security, explore how the 24-word recovery phrase is created, … Read more

Sum of Square Roots of First N Numbers in Python

There are several methods to calculate the sum of the square roots of the first n numbers. Basic Iteration The most straightforward solution is to simply iterate from 1 to n, calculate the square root of each number, and add it to a running total. Runtime: O(n) Approximate Closed Form Solution An approximate closed-form solution … Read more

Show Your Love with This Python One-Liner! Printing a Heart with Name (ASCII Art)

I just stumbled on this beautiful Python one-liner submitted by GitHub user ZenOfTech to our GitHub repository one-liner collection: The beautiful output: erILoveFi inxterILo nxterILoveFinxter veFinxterILoveFin inxterILoveFinxterILoveFinxterILoveFinxte inxterILoveFinxterILoveFinxterILoveFinxterI inxterILoveFinxterILoveFinxterILoveFinxterILo nxterILoveFinxterILoveFinxterILoveFinxterILov xterILoveFinxterILoveFinxterILoveFinxterILove terILoveFinxterILoveFinxterILoveFinxterILoveF erILoveFinxterILoveFinxterILoveFinxterILoveFi rILoveFinxterILoveFinxterILoveFinxterILoveFin LoveFinxterILoveFinxterILoveFinxterILoveFin veFinxterILoveFinxterILoveFinxterILoveFin eFinxterILoveFinxterILoveFinxterILoveFinx nxterILoveFinxterILoveFinxterILoveFin terILoveFinxterILoveFinxterILoveFin rILoveFinxterILoveFinxterILoveFin oveFinxterILoveFinxterILoveFi FinxterILoveFinxterILoveF xterILoveFinxterILove ILoveFinxterILo eFinxterI xte e You can easily change it by adding the … Read more

Python Integer to Hex — The Ultimate Guide

Working with different number systems and their representations is a common practice in the world of programming. One such conversion involves changing integer values into their corresponding hexadecimal representations. In Python, this transformation can be achieved with ease by utilizing built-in functions and string formatting techniques. Hexadecimal, also known as base-16, is a number system … Read more

How I Created a Football Prediction App on Streamlit

This tutorial shows you how I created a model to predict football results using Poisson distribution. You’ll learn how I designed an interactive dashboard on Streamlit where our users can select a team and get to know the odds of a home win, draw, or away win. Here’s a live demo of using the app … Read more

How to Normalize a NumPy Matrix

In this blog post, we’ll discuss how to normalize a matrix using the popular Python library NumPy. But first things first: 👇 What is Normalization? In mathematics, normalizing refers to making something standardized or regular. Normalization of a matrix is a process of scaling the matrix so that the elements of the matrix have a … Read more

How to Convert an Octal Escape Sequence in Python – And Vice Versa?

This tutorial will show you how to convert an But let’s quickly recap what an octal escape sequence is in the first place! 👇 What Is An Octal Escape Sequence?💡 An Octal Escape Sequence is a backslash followed by 1-3 octal digits (0-7) such as \150 which encodes the ASCII character ‘h’. Each octal escape … Read more

Python Int to Hex | String Formatting

💬 Question: How to use Python’s string formatting capabilities — f-strings, percentage operator, format(), string.format() — to convert an integer to a hexadecimal string? Lowercase Solution without ‘0x’ Prefix You can convert an integer my_int to a simple lowercase hex string without ‘0x’ prefix by using any of the four string formatting variants—all based on … Read more

Print Hex with Uppercase Letters in Python

Quick answer: 👇 Use the f-string expression f’0x{val:X}’ to convert an integer val to a hexadecimal string using uppercase hex letters as set by the capitalized hex format specifier X. Optionally, you can add the prefix ‘0x’ in front of this. Example: 💡 Note: This is Method 3 of this tutorial, and it is presented … Read more

Python Hex String to Integer Array or List

Problem Formulation Given a hex string, i.e., a string of hexadecimal digits like so: 01ffa87135affcd45deebe You want to convert a batch of k hex digits to an integer. For example with k=2, you obtain the following batches of two hex digits each: 01 ff a8 71 35 af fc d4 5d ee be Now, convert … Read more

Python Hex String to Little Endian (Bytes/Integer)

What Is Big/Little Endian? Computers perform computations on data that is represented with bytes, i.e., sequences of 0s and 1s. A computer program manipulates data by loading data from memory (RAM, Cache, Disk, SSD), performing computations based on that data, and storing the resulting data back into the memory. A computer program loads and stores … Read more