My First Hello, World in C. Very proud!

preview_player
Показать описание
Sorry for no camera. I moved to a different apartment recently and couldn't find it.

References:
Рекомендации по теме
Комментарии
Автор

I lied. This was not my first Hello World. I'm really sorry.

TsodingDaily
Автор

The technique is pretty clever and interesting but I'm just wondering how someone can get this gud at using emacs

MrInsanepotato
Автор

Nitpick: You can iterate until x = 0 in the case when your encoded string doesn't have one or more characters at the end, which are the first (0th) in your character table. But it's fine for a Hello World specifically.
Also what you tweeted has obviously the index table encoded in 4-bit chunks, which still fits into 64 bits - the index tables are different.

_general_error
Автор

Don't worry, all globals are initialized to zero for default, unlike locals.

And good job, it's a good video :D

Akn
Автор

After watching this video, I just realized that I accidentally watched this half hour long video

tonyli
Автор

the version shown in the video makes perfect sense since it ANDs with 0xf (1111) instead of 0377 and thus the right shifts don't go out of control. What threw me trying to decipher this is that the 0377 version works. _Why_ does it work? Right shift by amounts larger than the type are undefined. The first iteration yields a shift amount of 0x208 (it's over 500), which is way larger than 64. Case in point, 0x1 >> 200 gives some giant garbage number rather than any hex number with a single 1, 2, 4, or 8 digit.

I actually paused the video at 0:48 once I noticed the 0xF in there and made a second attempt at deciphering it and succeeded. My best guess for the 0377 version is that the compiler is wrapping the shift amount mod 64, since 0x208 % 64 yields 8 and 0x2a0 % 64 yields 32. I have a whole table I wrote up in my text editor but pasting it here would be impossible cause youtube would fuck up the heavily whitespaced formatting if I did. That said I ended up with this, which reads as "Hello World" to me

0 726F6C6564574820 >> 8 726F6C65645748
1 726F6C6564574820 >> 32 726F6C65
2 726F6C6564574820 >> 40 726F6C
3 726F6C6564574820 >> 40 726F6C
4 726F6C6564574820 >> 48 726F
5 726F6C6564574820 >> 0 726F6C6564574820
6 726F6C6564574820 >> 16 726F6C656457
7 726F6C6564574820 >> 48 726F
8 726F6C6564574820 >> 56 72
9 726F6C6564574820 >> 40 726F6C
A 726F6C6564574820 >> 24 726F6C6564

(told you YT would fuck it up, they're supposed to be right-justified)

Anyway, I'll watch the video now.

BradenBest
Автор

I think that in the Twitter example the 4 bits shift and the & with 0377 still works because u've just considered (I guess) the indices made of 4 bits each (instead of 3 ) so 11*4 = 44 bits for all indexes + 4 bits for '\0' which still fits in a 64bits int, that's why the hexadecimal number (dx) is made of 12 digits (48 bits). I haven't fully understood the 0377 mask even with the 4 bits for an index, you should be able to remove it and it should work anyway; if u want to use a mask for 4 bits indices is & 15 (like & 7 for the 3 bits).
Tsoding hid it so well that he couldn't remind the explanation himself, goal achieved!
(And btw don't take this explanation too seriously, I wrote it just because I was curious) :)

michelezenoni
Автор

Haha, I wonder if you could even make it so that all of the extra numbers like the 3s and the 7 are themselves obtained via shifting the index. Of course, this would start to depend on your message containing index 3 and 7...

ThatBastardOverThere
Автор

this was great, a lot of neat patterns

Gahlfe
Автор

I would have had the indecies be 4 bit values, just because working with nybbles is (usually) significantly easier that with triples (although, that's a very good reason *not* to use nybbles in this case). I would guess that that's what you actually did the first time, which is why that's how you explained it, and why that's what's in your original code (notice also that the value of `dx` *is* different in the original). Also, in the original, you're missing the single-byte mask...but it works, because the value is being implicitly cast to a single byte anyway.

MCLooyverse
Автор

You can also fit more characters in the table by reducing the size of each character. If it's ASCII-only, then you can just use 7 bits per character, which bumps you up from 8 to 9 characters. If 26 alphabetic characters is enough and you add 65/0x41/0101 to that index, you can even bump it up to 5 bits per character / 12 characters.

mikkmikimikk
Автор

The way I print a list is either to emit "\b\b]" at the end, or I create a string, which can be easily modified, then printed in one go.

MCLooyverse
Автор

Thankfully I watched the "What is IO Monad" video so I can understand that line of code with >>=

xetera
Автор

You can make more videos of obfuscation?

Makotom
Автор

the indexes could fit in 32 bits if you make sure your last index references one of the first 4 characters

antiMatterDynamit
Автор

The fastest hello world known to mankind.

TheMuffinMan
Автор

This reminds me of ArnoldC. The best programming language out there! Get to the Chopper!

tenj
Автор

you could use huffman encoding to store indexes in a 32 bit integer and the encoding itself in a 16 bit one. You'd save extra 16 bits :)

BRO-srvj
Автор

If you would put one more extra zero byte to the index, you could change the & 7 to & 56 to omit the << 3 and parentesis!
Additionally, you might change >>= 3 to /= 8 and & 0xFF to * 256 to make things shorter.
And im not sure abort that one, but can one use long long on all platforms to get rid of the second include?

whythosenames
Автор

Thank you for inspiring me to leave coding.

provakar