- 01Getting Started
- 02Your First Output (System.out.println)
- 03Working with Variables
- 04Conditionals (if statements)
- 05Loops (for statements)
- 06Writing a Method (Function)
- 07Working with Arrays
- 08Loops (while statements)
- 09Classes (Object-Oriented Programming)
- 10Error Handling (try-catch)
- 11Sorting an Array
- 12Recursive Functions
- 13Using the Standard Library
- 14The switch Statement
- 15The Ternary Operator
- 16Inheritance (Extending a Class)
- 17Writing Comments
- 18Logical Operators (&&, ||, !)
- 19Constants (final)
- 20Splitting and Joining Strings (split, join)
- 21Writing Null-Safe Code
- 22Searching a Collection (contains)
- 23Transforming an Array (Stream map)
- 24Two-Dimensional Arrays (Tabular Data)
- 25Writing a Custom Exception Class
- 26Method Overloading
- 27Working with HashSet (Sets)
- 28Checking Correctness with assert (Your First Step into Testing)
- 29Higher-Order Functions (Passing a Function as an Argument)
- 30Stacks and Queues (Basic Data Structures)
- 31Type Conversion (Casting) Basics
- 32Intro to Regular Expressions (Pattern Matching)
- 33The Binary Search Algorithm
- 34Building a Caesar Cipher (a Character-Shifting Cipher)
- 35Understanding How Bubble Sort Works
- 36Building and Displaying Dates (Basic Year/Month/Day Operations)
- 37Writing Multiple Test Cases Together
- 38Speeding Up Calculations with Memoization (Caching)
- 39Normalizing Strings (trim, Unifying Case)
- 40Shallow Copy vs. Deep Copy
- 41Enum (Enumerated Types) Basics
- 42Flattening a List
- 43Reversing a String and Checking for Palindromes
- 44Pairing Up Two Lists (the zip operation)
- 45Rounding Numbers (floor, ceil, round)
- 46Multi-Line Strings (Text Blocks)
- 47Functions That Return Multiple Values (record)
- 48Finding the GCD and LCM (the Euclidean Algorithm)
- 49Formatting Numbers (Padding Digits, Decimal Places)
- 50Cleanup Logic with try/catch/finally
- 51Writing Generic Functions
- 52File Reading and Writing Basics
- 53Generating Random Numbers
- 54Bitwise Operators (AND, OR, XOR, shifts)
- 55Reading Command-Line Arguments
- 56Waiting for a Fixed Amount of Time (Thread.sleep)
- 57Watch Out for Floating-Point Rounding Errors
- 58Reading from Standard Input
- 59FizzBuzz (the Classic Practice Problem)
- 60Checking Whether a Number Is Prime
- 61Set Operations (Union, Intersection, Difference)
- 62Converting Number Bases (Binary, Hex)
- 63Checking Balanced Parentheses (an Application of Stacks)
- 64Checking Whether Two Words Are Anagrams
- 65Checking Whether a Year Is a Leap Year
- 66Converting Temperature (Celsius to Fahrenheit)
- 67Prime Factorization
- 68[Applied] Build a Simple Inventory Management Tool
Converting Number Bases (Binary, Hex)
This lesson covers converting number bases in Java — binary, hex, and more — so you understand how a computer represents numbers internally. It's for anyone searching "Java number base conversion usage."
Integer.toBinaryString() and Integer.toHexString() convert a number into a binary or hexadecimal string. Going the other way, Integer.parseInt(string, radix) converts a string in that base back into a decimal number.
The example converts 42 into a binary string with Integer.toBinaryString(42), and into a hex string with Integer.toHexString(42). Having a dedicated method for each purpose is characteristic of Java.
A common early mistake is the relationship between a base's radix and its actual values. Hexadecimal uses the letters a through f after 0 through 9 — a notation rule that takes some getting used to compared to decimal intuition.
Binary is commonly used inside a computer, and hexadecimal is commonly used for things like color codes — worthwhile foundational knowledge to remember.
🧪 This site can't compile or run Java directly, so it checks on the spot whether what you typed matches the reference code (scoring happens entirely in your browser — nothing is sent anywhere).
