OK, enough just playing around with ChatGPT; let’s see if it can write some code:
Continue reading “ChatGPT Writes Decent Code For Binary to Decimal Conversion”
Binary Numbers, Binary Code, and Binary Logic
OK, enough just playing around with ChatGPT; let’s see if it can write some code:
Continue reading “ChatGPT Writes Decent Code For Binary to Decimal Conversion”
Continuing with my recent conversation with ChatGPT I thought I’d ask it if it could write haiku about binary numbers, like I have:
Nice, but I was looking for the 5/7/5 syllable format (this is 6/8/5), so I asked for that specifically:
Like everyone else these days I’ve been playing around with ChatGPT:
Continue reading “What ChatGPT Knows About Exploring Binary (Spoiler: Not Much)”
I wrote a simple byte to decimal converter app less than two months into starting to learn Jetpack Compose. Now that I have more experience with Compose — in developing a real app and by participating on the #compose channel on Slack (login required) — I wanted to update this demo app to reflect my current understanding of best practices.
Continue reading “Jetpack Compose Byte Converter App: 2022 Version”
IntelliJ IDEA has a code inspection for Kotlin that will warn you if a decimal floating-point literal exceeds the precision of its type (Float or Double). It will suggest an equivalent literal (one that maps to the same binary floating-point number) that has fewer digits, or has the same number of digits but is closer to the floating-point number.
For Doubles for example, every literal over 17-digits should be flagged, since it never takes more than 17 digits to specify any double-precision binary floating-point value. Literals with 16 or 17 digits should be flagged if there is a replacement that is shorter or closer. And no literal with 15 digits or fewer should ever be flagged, since doubles have of 15-digits of precision.
But IntelliJ doesn’t always adhere to that, like when it suggests an 18-digit replacement for a 13-digit literal!
Continue reading “Anomalies In IntelliJ Kotlin Floating-Point Literal Inspection”
Which is bigger, 64! or 264? 64! is, because it follows from a proof by induction for any integer n greater than or equal to 4. It’s also easy to just reason that 64! is bigger: 264 is 64 factors of 2, whereas 64! has 64 factors, except all but one of them (1) are 2 or greater.
When I saw this problem though I wondered if I could solve it in another way: Could the factors of two alone in 64! be greater than 264? As it turns out, almost.
Do you prefer hexadecimal numbers written with uppercase letters (A-F) or lowercase letters (a-f)?
For example, do you prefer the integer 3102965292 written as B8F37E2C or b8f37e2c? Do you prefer the floating-point number 126.976 written as 0x1.fbe76cp6 or 0x1.FBE76Cp6?
I ran this poll on my sidebar, and after 96 responses, about 70% are “prefer uppercase” and about 9% are “prefer lowercase”. What do you think? (For the “depends on context” answer I meant things other than numeric values, like the memory representation of strings. However, for the purposes of this article, please answer with just numeric values in mind.)
Continue reading “Hexadecimal Numbers: Uppercase or Lowercase?”
I see these from time to time, but I don’t always capture them; here’s one I saw recently while playing a podcast:
(According to Castbox, this is an error in the ad and is out of their control.)
I’ve been learning Jetpack Compose and Kotlin (and Android for that matter) so I decided to create a simple binary conversion app to demonstrate how easy it is to create (at least basic) UI in Compose.
(This app has been updated; see Jetpack Compose Byte Converter App: 2022 Version.)
Continue reading “A Simple Binary To Decimal Converter App In Jetpack Compose”
For my recent search for short examples of double rounding errors in decimal to double to float conversions I wrote a Kotlin program to generate and test random decimal strings. While this was sufficient to find examples, I realized I could do a more direct search by generating only decimal strings with the underlying double rounding error bit patterns. I’ll show you the Java BigDecimal based Kotlin program I wrote for this purpose.
Continue reading “Direct Generation of Double Rounding Error Conversions in Kotlin”
In my previous exploration of double rounding errors in decimal to float conversions I showed two decimal numbers that experienced a double rounding error when converted to float (single-precision) through an intermediate double (double-precision). I generated the examples indirectly by setting bit combinations that forced the error, using their corresponding exact decimal representations. As a result, the decimal numbers were long (55 digits each). Mark Dickinson derived a much shorter 17 digit example, but I hadn’t contemplated how to generate even shorter numbers — or whether they existed at all — until Per Vognsen wrote me recently to ask.
The easiest way for me to approach Per’s question was to search for examples, rather than try to find a way to construct them. As such, I wrote a simple Kotlin1 program to generate decimal strings and check them. I tested all float-range (including subnormal) decimal numbers of 9 digits or fewer, and tens of billions of random 10 to 17 digit float-range (normal only) numbers. I found example 7 to 17 digit numbers that, when converted to float through a double, suffer a double rounding error.
Continue reading “Double Rounding Errors in Decimal to Double to Float Conversions”
Google is celebrating Leibniz’s 372nd birthday today, recognizing him for his writings on binary numbers and binary arithmetic:
The drawing shows the binary code for the ASCII characters that spell “Google”: