Why every 2016 blocks? Does it have to do with maths?
Because it's meant to be an average of 144 blocks a day for 14 days... I think it's a fairly reasonable sample size.
Knowing from programming, hash functions produce a fixed-length string.
SHA256 of the string "
a" is: ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb
^That output is not a number. You're saying that hash is just a number that is the subject of a compression function. Yes, target seems to be a number since you say "they want the hash to fall below the target". But... Why do you say that hash is a number?
But it is a number? It's not denary but it's a number? Which sorts of programming have you done in the past? Have you done much with statically typed objects (c#/java/c++/c/assembly)?
Do you know binary? Is 0110 a number, can we agree it's 6?
Going back to binary, we can take the last four digits of your hex string above that forms the hash 48bb
4 = 4 (and since it's a base 16 number, we multiply it by 16^4)
8 = 8 (and since it's a base 16 number, we multiply it by 16^3)
b = 11 (1101 and since it's a base 16 number, we mulitply it by 16^2)
b = 11 (and we times it by 16^0)
I get 48bb to be 18619 (quickly input so may be wrong).
Before saying this is a stupid way to represent numbers or anything, take yourself back to any lessons you may have had discussing binary and look up what a 'nibble' is in binary... Hexadecimal is just a way to represent 4 binary digits (a nibble).
Wait... So nodes are randomly choosing other nodes? How's a node looks like? Is it a string?
Nodes are randomly selected, but if you think about the rate of computation in a machine and that you're just sending a tiny amount of data or even just pinging the node to check it has that port open (I think covering this is a bit out of scope here though).
A node, in any case on the internet is represented by it's SOCKET... In bitcoin's case, it's represented by the node's IP address plus the port.
So having bitcoin core open means that I'm having a port open too? I thought that IPs are something hidden in the bitcoin world. I thought everything is anonymous.
The anonymity is a misconception. Hosting a node can actually be anonymous if it's routed through TOR (The Onion Router), however, hosting it over the light web doesn't make it anonymous at all.
Bitcoin itself is pseudoanonymous for the time being (however this will likely be subject to change in the coming years)... You can currently see where funds have come from and are going to. You may want to look into Dash, Monero or Grin to see how they achieve transaction anonymity.