Results for “Numbers & numeric validation”
Small, practical examples. Search by task or narrow things down below.
Convert ASCII text to lowercase safely
C++: Cast each byte to unsigned char before using the cctype function.
C++✓ Tested
Convert hexadecimal text to bytes
Python: Use bytes.fromhex for a readable byte representation and hex for the reverse conversion.
Python✓ Tested
Convert Unix seconds to an offset-aware timestamp
C#: DateTimeOffset preserves the UTC offset explicitly.
C#✓ Tested
Count Unicode code points
Java: Use codePointCount when supplementary characters should count as one rather than two UTF-16 units.
Java✓ Tested
Detect integer addition overflow
Java: Math.addExact throws rather than silently wrapping on overflow.
Java✓ Tested
Detect integer overflow with checked
C#: A checked arithmetic block throws instead of silently wrapping an integer result.
C#✓ Tested
Dispatch values with wildcard patterns
PowerShell: Switch -Wildcard interprets shell-style matching patterns for each clause.
PowerShell✓ Tested
Display an integer as unsigned
Java: Use unsigned conversion methods when interpreting a fixed-width bit pattern.
Java✓ Tested
Divide decimal values with controlled precision
Java: Choose both scale and rounding for a quotient that does not terminate in base ten.
Java✓ Tested
Divide negative integers with floor rounding
Java: floorDiv and floorMod provide consistent floor-based quotient and remainder.
Java✓ Tested
Encode and decode binary data as Base64
Python: Use Base64 when a text format must carry bytes; it is encoding, not encryption.
Python✓ Tested
Enumerate Unicode code points
C#: EnumerateRunes combines surrogate pairs into Unicode scalar values.
C#✓ Tested