Tales from the jar side: Unsigned integers in real life, Dogecoin and eccentric billionaires, and a cover of The Archies that actually works
Is this all an elaborate way to convince myself to keep away from cryptocurrencies? Nonsense. Okay, possibly. Maybe. Whatever.
Welcome to Tales from the jar side, the Kousen IT newsletter, for the week of May 2 - 9, 2021. This week I taught two classes on the O’Reilly Learning Platform, one on Reactive Spring and one on Java Testing with JUnit 5, both in the Asia/Pacific time zones. The classes went quite well, but the 9 1/2 hour time difference between where I live and IST (India Standard Time) means I’m still tired.
This week unsigned integers made the news, believe it or not. Since they are actually relevant to what I do, let me take a moment to talk about them.
If you’re not already a subscriber, please consider becoming a jarhead by clicking this button:
Kotlin 1.5 Released
I was going to start writing about unsigned integers, but I got bored just saying that, so I can only imagine how you felt about it. It is relevant this week, though, so let me try to sum up.
Computers are binary, meaning they store only ones and zeros. When you store a number in a computer, it converts it to binary, where each digit represents a power of two (1s, 2s, 4s, 8s, etc). Therefore 5 is represented as 101 (one 4, zero 2s, and one 1), 8 is 1000 (one 8 and the rest zeros), and 42 is 101010 (one 32, one 8, and one 2) as well as being the ultimate answer to life, the universe, and everything.
In the Java world, of which Kotlin is a part, integers are stored using four bytes, and each byte is eight bits. Each of those binary digits is a bit, so with four bytes of eight bits each you get 2^32 possible values (that’s 2 raised to the power of 32 — there’s no built-in way in this editor to show an exponent). For a regular integer we have negative numbers too, so the range of available Int values goes from -2^31 up to 2^31 - 1 (to leave room for zero), which is -2,147,483,648 up to 2,147,283,647. Unsigned integers, on the other hand go from zero to 2^32 - 1, or from 0 up to 4,294,967,295.
The easy way to remember the sizes is:
2^10 is 1K as in kilo, or 1024, the first binary greater than 1 thousand
2^20 is 1M as in meg, or 1,048,576, the first binary greater than 1 million
2^30 is 1G as in gig, or 1,073,741,824, the first binary over 1 billion.
Therefore 2^31 = 2 * 2^30 is the first binary above two billion, and 2^32 = 4 * 2^30 is the first binary above four billion.
When I was writing my Kotlin Cookbook, the unsigned types UInt and ULong (not the tea) were still considered experimental. I considered adding recipes (again, not for the tea) for them to my book, but I left them out. Now I have a reason to use them.
One other note before I get to that. I upgraded my GitHub repository for the book to Kotlin 1.5. The only functions I had to change were the deprecated String functions toLowerCase, toUpperCase, and capitalize, in favor of lowercase, uppercase, and, well, let me show you:
The replacements lowercase and uppercase make sense, because when you internationalize you want to make sure you’re consistent with the local country and language (what Java calls a locale). The last one is wild, though. IntelliJ IDEA does that full replacement automatically as one long line, taking a single, easy method and changing it to multiple methods and an if statement. Oh well. So be it.
Most of the library changes are summarized in this video from JetBrains:
Btw, while I understand adding useful functions to the library is a good thing, the less said about firstNotNullOfOrNull the better.
Why do unsigned integers matter? They certainly matter this week to Berkshire Hathaway, the investment group managed by billionaire Warren Buffett.
Fun with Unsigned Integers
Billionaires are strange people (more on that later), so it’s not surprising to find them doing eccentric things. For Buffett and Berkshire Hathaway, one of those eccentricities is that he has never allowed the stock price to split. When you split a stock, you cut the price per share and increase the number of shares so the total value remains the same. For example, if the price before the split was $100 and there were 1 million shares, a two-for-one split would make the price $50 with 2 million shares. The outstanding value of the all the shares is still $100 million, but now individual shares are more affordable.
Affordability is not the primary issue for Warren Buffett. Supposedly to encourage a “buy and hold” strategy, the primary stock for Berkshire Hathaway, BRK.A, has never split. Ever. On Friday, the price for BRK.A on the New York Stock Exchange reached $435,120.00 per share.
That’s a lot (to make a massive understatement), but it’s still way less than 4 billion. So what’s the problem?
The issue is that the reporting systems don’t want to deal with fractions. Representing integers in binary is fine, but if you try to store fractions all sorts of weird things happen. For example, the base 10 value 0.1 is an infinite repeating decimal in binary, 0.000110011…. Even when you use double precision numbers in Java, which have 17 decimal places of precision, a simple subtraction like 1.0 - 0.1 can give you round off errors.
(Or at least it used to. Apparently recent versions of Java have improved that, and the demo I was going to include now returns 0.9, as it should. That’s a good thing, though it does mess up my demo.)
All of this is supposed to remind you of the scheme used in the movie Office Space, where they took the remainder each time interest was added to an account and kept it for themselves.
To avoid all this, the developers who wrote the reporting systems for NYSE, NASDAQ, etc, decided to multiply the stock price by 10,000, do any necessary math with integers, and then divide the result by 10,000 again. That way they can report four-decimal place precision without having to deal with any actual fractions.
But yikes, if you move the BRK.A stock price four decimal places to the left, you get 4,351,200,000, and now you’ve exceeded the maximum size of an unsigned integer. What happens in a computer when you overflow an integer type? According to two’s complement arithmetic, you wrap around to the lower limit and keep going. So the stock would go to zero and start upward again.
Can you imagine the resulting frenzy? Tons of investors would want to grab shares at what seemed like a massive discount, and all those people who already had shares (like Buffett) would be panicking at the apparent crash in value. So the exchanges went “Price not available, sorry” and stopped accepting orders.
The whole event is described in this article in The Register, where they actually had the temerity to refer to the situation as a Buffett overflow.
If this all reminds you of the Y2K problem, yeah, that’s it exactly. The fix is to store the value in an unsigned ULong instead of a UInt, which would add a few quadrillion to the available numbers. Supposedly a fix is coming.
Speaking of Eccentric Billionaires
Check out this sentence, from the Wikipedia page on Dogecoin:
In February 2021, Dogecoin hit a new high price of $0.08 following Twitter encouragement from [Elon] Musk, Snoop Dogg and Gene Simmons.
Those are three people I never expected to to see in the same sentence. Keep in mind that statement is from three months ago.
Dogecoin (Doge is pronounced DOHJ, or DOHZH, before the word coin) was created as a joke based on the Doge meme:
The Doge meme for the Shiba Inu dog supposedly peaked way back in 2013:
But a couple of developers back then also decided, as a joke, to create a cryptocurrency based on the meme, called Dogecoin. The idea was to make a friendly community that could buy and sell the coins with no transaction fees, and they contributed to various charities over the years.
The currency went along, minding its own business, until people like Elon Musk got involved. He started tweeting out his support. Then Mark Cuban (another odd billionaire and owner of the NBA Dallas Mavericks) decided to allow purchasing of Mavs tickets and products with Dogecoin. Others jumped on the bandwagon.
Remember, this is a “currency” backed by NOTHING. It’s a gag that went viral. That’s all. In fact, the value of one Dogecoin on November 3, 2020 was $0.002507. That’s a quarter of a penny per share.
Um, check out the price chart over the last five months:
After briefly hitting $0.72, the price on Friday closed at $0.6621, or just over 66 cents a share. The price is now 264 times what it was in November. If you’d bought $100 worth of Dogecoin back then, it would now be worth $26,410. Woof. So wow, indeed.
I screen-grabbed that data Saturday afternoon. Elon Musk is scheduled to appear on Saturday Night Live tonight. (Why? I have no idea either.)
That’s Elon Musk with Miley Cyrus and Kid Laroi (?), and then somebody photoshopped a Doge picture in there. Dogecoin traders are planning watch parties. Musk has been in trouble with the SEC before, and if he does anything to push the coin he could be in trouble again.
Bloomberg has warned that anyone investing in Dogecoin should be prepared to lose all their money. The entire situation was nicely summarized by Charlie Wenzel in Bloomburg this way:
Update Sunday afternoon: Musk on SNL was apparently mediocre and didn’t push the currency. The price of Dogecoin dropped to 0.4593 by 6 am and is currently at 0.5679. As they saying goes, the best way to make a small fortune in a volatile market is to start with a large fortune.
For Some Real Value
If you want something of actual value, The Pragmatic Bookshelf is still in the midst of its Leader of the Pack sale. With the coupon code Pack2021 you can get 50% off the price of a whole series of business books, one of which is my upcoming book Help Your Boss Help You.
The sale ends on May 14th (this coming Friday), so get them while the getting is good.
Speaking of billionaires, I refer to one in my book. I have a section in the Managing the Chain of Command chapter that I originally called Mark Cuban Is An Idiot, but my editor made me change the title to keep from getting sued. It references an old Forbes article where Cuban admitted to not only violating the chain of command by repeatedly trying to make direct connections with top-level executives (bypassing his own boss in the process), but then defended himself by claiming he cared more about the company than his boss did. Those were mistakes of ambition, which are usually not a problem for aggressive white males in the financial industry, but he did such damage to the relationship with his boss that he pretty much had to leave. The fact that he told this story years later and still thought he was right showed he learned nothing from the experience. The only actual job he can hold is CEO, because he doesn’t understand how to work for anyone else.
Remember, billionaires are hoarders, with all the psychological damage associated with that term. They’re just like those people on the TV show Hoarders, just that they hoard money rather than boxes of garbage. They’re not people to be emulated or envied.
On the other hand, if over 100 million people decide to buy my book, maybe I can become a billionaire and I’ll let you know what it’s like from the inside. Then I can even buy some Dogecoin and maybe a few shares of BRK.A stock. I’ll let you know.
A Few Miscellaneous Tweets
If you’re aware of furry culture, this may blow your mind.
So many of the replies were of the form: Please no! I’ll never be able to unsee that!
Here’s a comment about BDL, my home airport, which I’ll be using again starting in the Fall:
I can vouch for that assessment.
This is charming:
Indeed.
Finally, did you know Wilson Pickett covered The Archies?
Now you know. I wanted to give John Scalzi credit for this, but if you want to bypass Twitter and go to the song directly:
Sugar. Honey, honey. Even the key change works. Now try getting that out of your head.
As a reminder, you can see all my upcoming training courses on the O’Reilly Learning Platform here and all the upcoming NFJS Virtual Workshops here.
Last week:
Reactive Spring, on the O’Reilly Learning Platform (Asia/Pacific time)
Java Testing with JUnit 5, ditto
This week:
Managing Your Manager, on the O’Reilly Learning Platform
Day 1 of Spring and Spring Boot in Three Weeks, ditto
Modern Android Development, an NFJS Virtual Workshop