- Feature Articles
- CodeSOD
-
Error'd
- Most Recent Articles
- Stop Poking Me!
- Operation Erred Successfully
- A Dark Turn
- Nothing Doing
- Home By Another Way
- Coast Star
- Forsooth
- Epic
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
01100110 01110010 01101001 01110011 01110100
Admin
@nerd4sale you forgot the 00100001 at the end
Admin
We should name that a "Bugificator Pattern".
Admin
I get confused newbies asking how to convert an integer into its binary representation from time to time, to use with bitmasks and the like (i.e. not for printing to screen or anything else requiring a string). Takes all my diplomacy not to facepalm myself so hard my hand goes through the back of my skull.
Admin
I guess you are just too young to remember BCD.
Admin
Wow Remy, your WTF-fu is superior to mine. You have uncovered a level of WTAF that I missed completely.
taskDetail is a (int) bit mask, and as you have described, here it gets converted to a long which is the decimal interpretation of the binary value. Then it gets passed to the JavaScript front end via JSON. Once in JS, it gets converted back to an int using the call:
parseInt(binaryTaskDetail, 2)
and then used normally as a bit mask. How can this work? binaryTaskDetail is still an int in JS.
Well, parseInt expects a string as its first parameter, so JS helpfully does an implicit toString*, which is the binary value that we want, and we end up with the correct value, completely by accident.
The WTF is that it could have just been passed as an integer value the whole way through.
Admin
Probably a WTF, but not necessarily. There are a few edge cases where doing this ONCE outside of time critical code (talking true real-time where nS may matter) .
Admin
Ha, come on, the reason is f*cking simple. Just do a ToString on that number again, and then take a look at a specific position in order to find out if a specific bit has been set (1) or not (0). So easy, actually any beginner ought to understand that principle.
Admin
the x86 NPX (old style x87 floating point support) still has BCD instructions.
So do IBM zSystem mainframes.(1)
And probably others.
(1) For reasons of backward compatibility with System/360 compiled binaries.
Admin
It makes you feel a bit off, Remy? It makes me feel a bit 0ff...
Admin
BCD, sure, but these are DCB.
Admin
Binary is still a big mystery to a lot of programmers. Sometimes I think that's probably for the best. Just concern yourself with tasks at hand, the vast majority of which won't need any awareness of bits. Me? I can't help but seeing the path down to binary. The first computer I had at home was a loaner from an adult mentor. It was a 6800 based computer with 8 LEDs and 9 toggle switches. But even today, I will be with many year programming veterans who can't adequately explain what a byte is. Sad, but what are you going to do other than create sites like this one?
Admin
I once worked with a developer who thought that she needed to convert her integer into hex format before doing some more work with it. Thankfully, she recognized her error before she committed the code. (I'd like to think that she tested the code and realized how wrong everything was.)
Admin
As I mentioned earlier, the binary numbers "01100110 01110010 01101001 01110011 01110100" could represent ASCII code for a series of characters. To interpret these numbers as ASCII characters, we need to translate each binary number into its corresponding ASCII character. Here is how to do that:
01100110 = "f" 01110010 = "r" 01101001 = "i" 01110011 = "s" 01110100 = "t"
So when these binary numbers are interpreted as ASCII characters, they spell out the word "first". Again, this is just one possible interpretation of these numbers, and without more context it is impossible to say for sure what they mean.
Admin
Why a .toString()? You can easily do bitmask stuff with basic math on integers as well: Just use division and modulo to get the "number bit" (integer value 0 or 1) at the required decimal position you are interested in and compare it. And if you like, translate from integer to floating point, because that gives you a more accurate result ("If this zero would be a lot bigger, it would almost be a small portion of a 1!"). That looks so much more educated and science-y than querying positions in an ASCII string (typical coding bootcamp participant's level), justifying the "But I have a degree in computer science!" statement that got you into the job, and you can turn boring truth tables and flag checks into bar graphs and pie charts. PHBs will love it.
Admin
Fun fact, there was a ternary computer that was developed in USSR at some point in the distant past.
Admin
Nope. They spell out the non-word "frist".
For sure we can say that interpreted in EBCDIC, they mean nothing at all, since none of those byte values mean anything in the basic EBCDIC code pages.
Admin
Surely it's absolutely apparent that it's the floating point representation of 28,60297948?
Admin
It's clearly for an API that specifies inputs in decimal coded binary. Well, the specification used those words, but not necessarily in that order.
Admin
Lots of hardware can do BCD arithmetic, but in any computer language since the 1950s an integer variable is binary by default. I know of only two ways to write a program using BCD arithmetic: write in COBOL and define a field as BCD, or write in assembly language (where variables are defined only as an untyped space in memory) and directly call the BCD instructions.