C# – Hex string to byte array

This article shows code for converting a hex string to a byte array, unit tests, and a speed comparison. First, this diagram shows the algorithm for converting a hex string to a byte array. To convert a hex string to a byte array, you need to loop through the hex string and convert two characters … Read more C# – Hex string to byte array

Solving whiteboard problems to prepare for coding interviews

Companies like to ask you to solve whiteboard problems during coding interviews. If it’s an in-person interview, they’ll ask you to solve the problem on a physical whiteboard. If it’s a remote interview, they’ll either have you solve the problem on a website like HackerRank, or they’ll ask you the question in a “digital whiteboard” … Read more Solving whiteboard problems to prepare for coding interviews

Algorithm Explained: Counting set bits in a 32-bit signed integer

Problem statement: Given a 32-bit signed integer, how many set bits are there? Ex: The number 15 has four bits set. In this article I’ll explain how I’d approach this problem. Approach How do I know if a bit is set? A bit can either be 0 or 1. A bit is set if its … Read more Algorithm Explained: Counting set bits in a 32-bit signed integer

Multithreaded quicksort in C#

One day I decided to challenge myself by trying to implement multithreaded quicksort. I wanted to see how it would compare to the built-in sort function – Array.Sort(). I came up with two algorithms that were 2-4x faster than Array.Sort(): Top-down: divide-fork-sort-merge Bottom-up: quicksort with fork-on-recursion After continuing to tinker, in attempts to further optimize, … Read more Multithreaded quicksort in C#