There have been multiple accounts created with the sole purpose of posting advertisement posts or replies containing unsolicited advertising.

Accounts which solely post advertisements, or persistently post them may be terminated.

programmer_humor

This magazine is from a federated server and may be incomplete. Browse more on the original instance.

s12 , in How to write Hello World

Umm… someone explain this code please?

magic_lobster_party , (edited )

Bit shift magic.

My guess is that all the individual characters of Hello World are found inside the 0xC894 number. Every 4 bits of x shows where in this number we can find the characters for Hello World.

You can read x right to left. (Skip the rightmost 0 as it’s immediately bit shifted away in first iteration)

3 becomes H
2 becomes e
1 becomes l
5 becomes o

etc.

I guess when we’ve exhausted all bits of x only 0 will be remaining for one final iteration, which translates to !

CanadaPlus , (edited )

Too readable. You’ve gotta encode the characters as the solutions of a polynomial over a finite field, implemented with linear feedback on the bit shifts. /s

s12 ,

I understand that the characters are probably encoded into that number, but I’m struggling to understand that C/C++ code.

EmptySlime ,

<span style="color:#323232;">#include <stdio.h>
</span><span style="color:#323232;">
</span><span style="color:#323232;">int main() {
</span><span style="color:#323232;">
</span><span style="color:#323232;">Long long x = 0x7165498511230;
</span><span style="color:#323232;">
</span><span style="color:#323232;">while (x) putchar(32 + ((0xC894A7875116601 >> ((x >>= 4) & 15) * 7) & 0x7F));
</span><span style="color:#323232;">
</span><span style="color:#323232;">return 0;
</span><span style="color:#323232;">}
</span>

Might be wrong on a few things here as I haven’t done C++ in a while, but my understanding is this. I’m sure you can guess that this is just a very cheekily written while loop to print the characters of “Hello, World!” but how does it work? So first off, all ASCII characters have an integer value. That 32 there is the value for the space character. So depending on what ((0xC894A7875116601 >> ((x >>= 4) & 15) * 7) & 0x7F)) evaluates down into you’ll get different characters. The value for “H” for example is 72 so that first iteration we know that term somehow evaluated to the number 40 as 72 - 32 = 40.

So how do we get there? That big number, 0xC894A7875116601 is getting shifted right some number of bits. Let’s start evaluating the parenthesis. (X >>= 4) means set x to be itself after bit shifting it right by 4 bits then whatever that number is we bitwise AND it with 15 or 1111 in binary. This essentially just means each iteration we discard the rightmost digit of 0x7165498511230, then pull out the new right most digit. So the first iteration the ((x >>= 4) & 15) term will evaluate to 3, then 2, then 1, then 1, etc until we run out of digits and the loop ends since effectively we’re just looking for x to be 0.

Next we take that number and multiply it by 7. Simple enough, now for that first iteration we have 21. So we shift that 0xC894A7875116601 right 21 bits, then bitwise AND that against 0x7F or 0111 1111 in binary. Just like the last time this means we’re just pulling out the last 7 bits of whatever that ends up being. Meaning our final value for that expression is gonna be some number between 0 and 127 that is finally added to 32 to tell us our character to print.

There are only 10 unique characters in “Hello, World!” So they just assigned each one a digit 0-9, making 0x7165498511230 essentially “0xdlroW ,olleH!” The first assignment happens before the first read, and the loop has a final iteration with x = 0 before it terminates. Which is how the “!” gets from one end to the other. So they took the decimal values for all those ASCII characters, subtracted 32 then smushed them all together in 7 bit chunks to make 0xC894A7875116601 the space is kinda hidden in the encoding since it was assigned 9 putting it right at the end which with the expression being 32 + stuff makes it 0 and there’s an infinitely assumed parade of 0s to the left of the C.

s12 ,

Thank you.

barsoap ,

32 is ASCII space, the highest number you need is 114 for r (or 122 for z if you want to be generic), that’s a range of 82 or 90 values.

The target string has 13 characters, a long long has 8 bytes or 16 nibbles – 13 fits into 16 so nibbles (the (x >>= 4) & 15) it is. Also the initial x happens to have 13 nibbles in it so that makes sense. But a nibble only has 16 values, not 82, so you need some kind of compression and that’s the rest of the math, no idea how it was derived.

If I were to write that thing I’d throw PAQ at it it can probably spit out an arithmetic coding that works, and look even more arcane as you wouldn’t have the obvious nibble steps. Or, wait, throw NEAT at it: Train it to, given a specific initial seed, produce a second seed and a character, score by edit distance. The problem space is small enough for the approach to be feasible even though it’s actually a terrible use of the technique, but using evolution will produce something that’s utterly, utterly inscrutable.

Rentlar , in Someone escaped the Matrix
haulyard ,
@haulyard@lemmy.world avatar

Wait is he still on the Azure Performance team?

TrickDacy ,

Nope. If he hadn’t quit, it would say “present” instead of July 2024

ArcaneSlime ,

But…it says “august 2017-present” on the screenshot I’m looking at? Right? Also, isn’t July 2024 like, next month?

tyler ,

It says 2023, not 24. Commenter typo’d. and the top number is correct. Bottom one is probably custom filled out, not based on actual work history.

SqueakyBeaver ,

Look under “Principal Software Development Engineer.” It says “2017-present”

TrickDacy ,

That’s the basis for my claim actually. The other position has a date not the word “present”. Which I now realize includes 2023 not this year, so I don’t know what the original question was getting at.

Rentlar ,

Azure needs him to care for Microsoft’s Golden Goose at his farm.

CaptDust , in Someone escaped the Matrix

Man is actually living the dream, the crazy son of a bitch did it.

variants ,

He has become a battery for AI

cypherpunks , (edited ) in How to write Hello World
@cypherpunks@lemmy.ml avatar

python -c ‘print((61966753*385408813*916167677<<2).to_bytes(11).decode())’

how?$ python >>> b"Hello World".hex() ‘48656c6c6f20576f726c64’ >>> 0x48656c6c6f20576f726c64 87521618088882533792115812 $ factor 87521618088882533792115812 87521618088882533792115812: 2 2 61966753 385408813 916167677

palordrolap ,

perl -le 'use bignum;print+pack"H22",(61966753*385408813*916167677<<2)->to_hex()'

Alas, Perl doesn't bignum by default

nifty , in It's easier to remember the IPs of good DNSes, too.
@nifty@lemmy.world avatar

I feel like I could learn Dutch, my English is already broken

zqwzzle , in Someone escaped the Matrix

Was woodworking another common one?

blindbunny , in Someone escaped the Matrix

Based

UndercoverUlrikHD , in Someone escaped the Matrix

Surprised it wasn’t woodworking

Skullgrid ,
@Skullgrid@lemmy.world avatar

nah, brings back memories from the Pragmatic Programmer cover

reboot6675 ,

“I no longer build software; I now make furniture out of wood”

Legendary

yeather , in Someone escaped the Matrix

Don’t be fooled he’s going out there to hsck tractors now.

Kowowow ,

Spend years automating small farm tasks that take minutes

uis ,
uis , (edited )
Okami_No_Rei , in Someone escaped the Matrix
@Okami_No_Rei@lemmy.world avatar

Farming? Really? Man of your talents?

Tetsuo ,

Seriously, some people are that good that you know they could do almost anything very well in a matter of days.

So why not ? I always have a lot of respect for someone that is willing to drastically change their lives in order to improve.

snooggums ,
@snooggums@midwest.social avatar

Huh, my first thought was that they went to the farm upstate where everyone’s pets end up.

ggppjj , (edited )

It’s a quote from a Star Wars show movie.

ech ,

*movie

ggppjj ,

Ah gee dang, you’re right. Thanks!

ech ,

Np!

MetaCubed ,

Its a quote from Rogue One if I’m not mistaken

9point6 ,

You don’t need to be skilled in something to get enjoyment out of it

Likewise you don’t necessarily get enjoyment out of something just because you’re skilled in it.

dustyData ,

It’s a peaceful life.

fibojoly ,

My entire career is based on “yeah but you’re good with computers and programming!” I just wanted to do fine arts and paint for fuck sake. And I could have made a career out of it, as history as since shown! Ah well. Maybe my kids will fare better, we’ll see.

kshade ,
@kshade@lemmy.world avatar

It’s never too late, especially if you can combine the two!

WhiskyTangoFoxtrot ,

Dirt cleans off a lot easier than blood.

cerement , in Someone escaped the Matrix
@cerement@slrpnk.net avatar
Anticorp ,

This is the true story of my life. I’m still working towards that last cell.

Schmoo ,

I’m speedrunning this shit.

SpaceCadet , in It's easier to remember the IPs of good DNSes, too.
@SpaceCadet@feddit.nl avatar

IPv6 = second system effect. It’s way too complicated for what was needed and this complexity hinders its adoption. We don’t need 100 ip addresses for every atom on the face of the earth and we never will.

They should have just added an octet to IPv4 and be done with it.

orangeboats , (edited )

Every time there’s a “just add an extra octet” argument, I feel some people are completely clueless about how hardware works.

Most hardware comes with 32-bit or 64-bit registers. (Recall that IPv6 came out just a year before the Nintendo 64.) By adding only an extra octet, thus having 40 bits for addressing, you are wasting 24 bits of a 64-bit register. Or wasting 24 bits of a 32-bit register pair. Either way, this is inefficient.

And there’s also the fact that the modern internet is actually reaching the upper limits of a hypothetical 64-bit IPv5: lemmy.world/comment/10727792. Do we want to spend yet another two decades just to transition to a newer protocol?

SpaceCadet , (edited )
@SpaceCadet@feddit.nl avatar

you are wasting 24 bits of a 64-bit register

You’re not “wasting” them if you just don’t need the extra bits, Are you wasting a 32-bit integer if your program only ever counts up to 1000000?

Even so when you do start to need them, you can gradually make the other bits available in the form of more octets. Like you can just define it as a.b.c.d.e = 0.a.b.c.d.e = 0.0.a.b.c.d.e = 0.0.0.a.b.c.d.e

Recall that IPv6 came out just a year before the Nintendo 64

If you’re worried about wasting registers it makes even less sense to switch from a 32-bit addressing space to a 128-bit one in one go.

Anyway, your explanation is a perfect example of “second system effect” at work. You get all caught up in the mistakes of the first system, in casu the lack of addressing bits, and then you go all out to correct those mistakes for your second system, giving it all the bits humanity could ever need before the heat death of the universe, while ignoring the real world implications of your choices. And now you are surprised that nobody wants to use your 128-bit abomination.

orangeboats , (edited )

You’re not “wasting” them if you just don’t need the extra bits

We are talking about addresses, not counters. An inherently hierarchical one at that (i.e. it goes from top to bottom using up all bits). If you don’t use the bits you are actually wasting them.

you can gradually make the other bits available in the form of more octets

So why didn’t we make other bits available for IPv4 gradually? Yeah, same issue as that: Forwards compatibility. If you meant that this “IPv5” standard should specify compulsory 64-bit support from the very beginning, then why are you arbitrarily restricting the use of some bits in the first place?

If you’re worried about wasting registers it makes even less sense to switch from a 32-bit addressing space to a 128-bit one in one go

All the 128 bits are used in IPv6. ;)

SpaceCadet ,
@SpaceCadet@feddit.nl avatar

We are talking about addresses, not counters. An inherently hierarchical one at that. If you don’t use the bits you are actually wasting them.

Bullshit.

I have a 64-bit computer, it can address up to 18.4 exabytes, but my computer only has 32GB, so I will never use the vast majority that address space. Am I “wasting” it?

All the 128 bits are used in IPv6. ;)

Yes they are all “used” but you don’t need them. We are not using 2^128 ip addresses in the world. In your own terminology: you are using 4 registers for a 2 register problem. That is much more wasteful in terms of hardware than using 40 bits to represent an ip address and wasting 24 bits.

orangeboats , (edited )

I have a 64-bit computer, it can address up to 18.4 exabytes, but my computer only has 32GB, so I will never use the vast majority that address space. Am I “wasting” it?

You are using the addressing bits in the form of virtual memory. Right now. Unless you run a unikernel system, then in that case you could be right, but I doubt it.

Anyway, this is apples and oranges. IP addresses are hierarchical by design (so you have subnets of subnets of subnets of …), memory addresses are flat for the most part, minus some x86 shenanigans.

Yes they are all “used” but you don’t need them. We are not using 2^128 ip addresses in the world.

But we do need them! The last 64 bits of your IPv6 addresses are randomized for privacy purposes, it’s either that or your MAC address is used for them. We may not be using those addresses simultaneously but they certainly are used.

Despite that, there still are plenty of empty spaces in IPv6, that’s true. But they will still be used in the future should the opportunity arise. Any “wastage” is artificial, not a built-in deficiency of the protocol. Whereas if we restricted the space to 40 bits, there will be 24 bits wasted forever no matter how.

hch12907 ,

Hm, didn’t the GP already address (pun unintended!) the 128-bit part?

He/she said the internet is reaching upper limits of 64 bits apparently and gave a value of 61 bits in the linked comment.

lambalicious OP ,

64-bit IPv5

64-bit IP would be IPv8, not IPv5.

eyeon ,

it’s not about using all 100 IP addresses for every atom

it’s about having large enough ranges to allocate them in ways that make sense instead of arbitrarily allocating them by availability

Case ,

Please don’t I barely understand subnetting as it is.

joel_feila ,
@joel_feila@lemmy.world avatar

That why we should adopt my ipv12. Its three levels of addresses rach 512 bit longs. One for host one for network and one what ever the heel else need. Planet that’s it we asogn each planet a 512 bit address

mlg , in It's easier to remember the IPs of good DNSes, too.
@mlg@lemmy.world avatar

Typing addresses in ipv4 is ingrained into my brain, but zero NATing with ipv6 is magical.

FiniteBanjo , in It's easier to remember the IPs of good DNSes, too.

The problem is we’re projected to run out of unique IPv4 addresses by 2003.

orangeboats ,

And we are facing the effects of it as we’re speaking. CGNAT and protocols like TURN were not invented without a reason.

lambalicious OP ,

Not a big deal. We’re projected to run out of years by 2000 and then the world will end.

PaintedSnail ,

And it took a lot of hard work by a lot of people to adopt new date standards to avoid that problem. Now it’s time to adopt new IP standards, and it’s going to take a lot of hard work by a lot of people.

joel_feila ,
@joel_feila@lemmy.world avatar

Oh god that brings back memories. Reallying dumb ones of people but memories none the less

moriquende , in Who lives in a Pineapple in the Algorithms Library for C? SpongeBob BinaryTreePants!

Depends on the year.

DAMunzy ,

I was thinking time of the year. Is it hot or cold. But then I thought, which one is for which?

  • All
  • Subscribed
  • Moderated
  • Favorites
  • [email protected]
  • random
  • lifeLocal
  • goranko
  • All magazines