Categories
Coding

HEX Code

Hex is abbreviated from Hexadecimal. It’s widely used by programmers and computer system engineers. To laypeople, Hex code is considered as an untouchable issue that is as much complicated as Quantum Mechanics.

In fact, Hex code already has a very popular and practical application in our life for many years.

IT’S COLOR PICKER.

You definitely used a similar function by your phone, computer or other electronic device. The color you picked is represented by 3 individual 2-digit Hex codes for the setting value of RGB ( abbreviated from Red, Green and Blue).

Hex is simply a new way to count!

Don’t be scared! It’s simply a new way to count.

If you can count 1 to 10, you definitely can count 1 to 16. The concept of Hex code is to collect and group things by 16. We gotta use A, B, C, D, E and F instead of 10, 11, 12, 13, 14 and 15, because a digit can only be represented by a character.

Try to count 1 to 16 by HEX way, it would like: 
1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F and 10(a carry here)

Notice that there's a carry when we count to 16. 
So the number becomes 2 digits to 10.

11 is NOT Eleven

Let's count 1 to 17 by Hex way this time, it would like:
1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F and 10(a carry here), 11

There’s still one thing that I haven’t told you. ‘0x’ is a mark MUST be put in front of a number to represent Hex code. As the example, you have ONE group (0x1, 0x2, 0x3, ….0xD, 0xE, 0xF and 0x10) with one left (0x11), so we can say you totally count 0x11. That’s 16 + 1 = 17.

Dose it make sense to you now ?

Let’s take a challenge to count more, like 44.

It would like:
1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F, 10 
(First group is done),  

11, 12, 13, 14, 15, 16 ,17, 18, 19, 1A, 1B, 1C, 1D, 1E, 1F, 20
(Now we have 2 groups, it's 16+16=32) 

21, 22, 23, 24, 25, 26, 27, 28, 29, 2A, 2B, 2C
(We finally count to 44, it's 16+16+12 = 44). 

As above, we know 44 is 0x2C in Hex.

If you are interested in this topic, please take a look at Wikipedia. There’s much detailed information there! https://en.wikipedia.org/wiki/Hexadecimal

Try more counting, and enjoy the new way to count!

Categories
Coding

Program Variable

Variables are drum BAGs!

Drum bag is important to drummers keep their drums safe, especially during a gig tour. But if you have a 22″ bass drum, there’ll be no way to fit in a 18″ drum bag! On other hand, if we put all 10″ and 12″ Toms into 20″ or 22″ bags which are original for bass drum, that does not only waste money but also your room space.

Drum bags
Variables are drum bags

time flies!

Decades ago, the hardware of computer, such as CPU, RAM, Hard Disc, Main board …etc., is extremely high cost. The constraint of hardware also extremely affected the development of software.

At the time, as a software engineer we had to consider not only the run-time efficient of programs but the compiled size of codes. So, choosing suitable size of variables during programming was a fundamental task.

Now a days, ‘Giga’ is already the basic unit of memory space and the speed of CPU frequency. For this reason, software engineers are more comfortable to deal with the annoying stuff, like the efficient, the size and the scalability. But they probably omit the details of programming at the same time.

Be aware of the size

Even the project of Moon-Travel is going to be reality in the near future, I still believe that being aware of the size of variables is basic and a good habit to software developer.

Devil is in the detail. In my engineer career, I encountered a lot of strange and wired bugs. Most of the bugs were the causes of overlooking the details. If we can spend time in studying something we don’t know, not skip it and pretend it’s not important, we’ll obtain something in return in the future. All efforts will pay off!