Forums - Open Redstone Engineers
Short and Sweet Hexadecimal Tutorial - Printable Version

+- Forums - Open Redstone Engineers (https://forum.openredstone.org)
+-- Forum: ORE General (https://forum.openredstone.org/forum-39.html)
+--- Forum: Tutorials (https://forum.openredstone.org/forum-24.html)
+---- Forum: Fundamental Tutorials (https://forum.openredstone.org/forum-25.html)
+---- Thread: Short and Sweet Hexadecimal Tutorial (/thread-1057.html)



Short and Sweet Hexadecimal Tutorial - Neogreenyew - 09-26-2013

Prerequisite for this tutorial is the knowledge of binary and binary arithmetic.

INFO: You won't learn anything from this post unless you have the will to learn.

Hexadecimal is base 16.

Binary is base 2, so the only numbers allowed are 0 and 1. In hexadecimal we can use the numbers 0-9 and the letters A-F.

First things first, let's get in the habit of writing binary values by grouping everything together into sets of 4.
For example:
0000000000000000 is equal to
0000 0000 0000 0000
Note that the 0's are grouped into sets of 4 now.

Back to the values of hexadecimal values. Below is a chart of the hexidecimal value (top) and the corresponding decimal value (bottom)

0 1 2 3 4 5 6 7 8 9 A B C D E F
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Pretty simple, eh?

Well now on to converting values from hexadecimal to decimal. There are 2 ways we can do this. We can either do it the extremely hard way, or the easy way. Which would you choose?

Let's first convert the decimal number 13 into hex. What is the corresponding value from the chart above?
That's right, it's D. So 13 in dec. = D in hex.

How about something larger than 15... let's convert 50 this time.

First let's convert this to binary.
50 in binary is equal to 32+16+2, which is 00110010.
Notice that I wrote that as an 8bit value; this is important.
Remember how we write our binary values as sets of 4? Let's do that to our result for the binary value of 50.

0011 0010

Let's integrate this into hexidecimal now. If we have a binary value of 1111 (the max value for that set of 4), we have the number 15. In hex, the decimal value of 15 is equal to F. So 1111 = F. This is why we write our binary values in sets of 4.

So to find the hexidecimal value of our number, all we have to do is convert each of the sets of 4 separately.

0011 = 3(decimal) = 3(hexidecimal)
0010 = 2(decimal) = 2(hexidecimal)

So our hexidecimal value is 3 2. Notice that I added a space between the 3 and the 2; this helps avoid errors such as if we had the values 1 and 2 next to each other. We wouldn't want to mix up the values 1 and 2 with the value of 12, would we?

So 50 in decimal is equal to 3 2 in hexidecimal.

Do this conversion on your own.

Convert the decimal value 122 into hex.

ANSWER:
122 dec. = 0111 1010 bin. = 7 A hex.


Now let's convert a hex value into decimal.

We have two ways to do this. We can either choose the easy way or the extremely annoying way. Which one would you like to do?

Of course you'd choose the annoying way, who wouldn't?!
Let's start off by converting the hex value of A F F 4 9 C 2 into binary.

A = 1010, F = 1111, F = 1111, 4 = 0100, 9 = 1001, C = 1100, 2 = 0010

Now put them all together.

1010 1111 1111 0100 1001 1100 0010

And convert that into decimal using the traditional method that you should already know by now.

"But wait! That's super annoying and long, there must be a better way."
You're right, there is! There is a simple function that we can use in order to simplify an annoying process like that.
Start off by converting any letters into their binary value.
That gives us 10 15 15 4 9 12 2

Now let's use two different functions.
The first is to multiply the value of each index by 16 raised to the index and add them all together.

(10 x 16^6)+(15 x 16^5)+(15 x 16^4)+(4 x 16^3)+(9 x 16^2)+(12 x 16^1)+(2 x 16^0)
Feel free to do this on a calculator.
After adding all of this up, your answer is 184502722.

Now there's another function (that I figured out all on my own Big Grin)

Multiply the number by 2^(4*index)
Here's what it looks like.
10(2^(4*6))+ 15(2^(4*5)) and so on...
Now this function can be simplified by just raising 2 to the previous index +4. I'll use 'n' to signify a random value in the next example

n(2^24)+n(2^20)+n(2^16)+n(2^12)+n(2^8)+n(2^4)+n(2^0)
Notice that the number that 2 is being raised to is counting up by 4 from the right to the left.


If you want to learn how to multiply hex values together, go ask someone else because I'm lazy (as you could probably tell by the lack of grammar in this post) and I don't feel like doing it right now.

Here's a helpful video that can teach you hex as well. Check out this guy's channel for more tips on binary and hex and even some coding.

http://www.youtube.com/watch?v=m1JtWKuTLR0
And here's the wiki page
http://en.wikipedia.org/wiki/Hexadecimal


RE: Short and Sweet Hexadecimal Tutorial - newomaster - 09-27-2013

Moved to the proper location. Nice tutorial Big Grin


RE: Short and Sweet Hexadecimal Tutorial - Neogreenyew - 09-27-2013

(09-27-2013, 01:38 AM)newomaster Wrote: Moved to the proper location. Nice tutorial Big Grin

whoops. didnt know i put it in the wrong spot

also i put like 2% effort into typing this... how is it good? XD


RE: Short and Sweet Hexadecimal Tutorial - Frontrider - 12-02-2013

You are wrong: no letters in hexadecimal. Numbers larger than nine are marked by letters but they are not letters...
Fix that.


RE: Short and Sweet Hexadecimal Tutorial - Neogreenyew - 12-15-2013

(12-02-2013, 02:53 PM)Frontrider Wrote: You are wrong: no letters in hexadecimal. Numbers larger than nine are marked by letters but they are not letters...
Fix that.

Nah it's fine... We say 0 and 1 for binary, but it's actually based on voltages when it comes to computing and you never hear people mention that when they teach binary.


RE: Short and Sweet Hexadecimal Tutorial - Somepotato - 12-16-2013

High and low baby.


RE: Short and Sweet Hexadecimal Tutorial - Neogreenyew - 12-17-2013

(12-16-2013, 06:15 AM)Somepotato Wrote: High and low baby.

Exactly

Well... now days aren't there more states? I think I read something about there being more than just high and low now days.


RE: Short and Sweet Hexadecimal Tutorial - greatgamer34 - 12-18-2013

With quantum computing, there are more than two states using qubits.


RE: Short and Sweet Hexadecimal Tutorial - Neogreenyew - 12-18-2013

(12-18-2013, 03:21 PM)greatgamer34 Wrote: With quantum computing, there are more than two states using qubits.

explain


RE: Short and Sweet Hexadecimal Tutorial - greatgamer34 - 12-19-2013

Quantum computing uses the spins on atoms as high/low, and many states in between including both 0 and 1 at the same time. Data like this is extremely volatile, along with the fact that there aren't many uses for it yet. Although as traditional computing standards use voltage running through wires, as those wires become smaller(Intel is using 22nm lithography and are planning to release new CPUs in 2014 Q2/3 with 14nm lithography, to put AMD in this, they're still at 32nm), the problem occurs when trying to send electrons through wires that are to small for them to fit it. This is where quantum computers true potential is unraveled. There are no "traditional" transistors. It's actually based on the spinning of atoms. The D-Wave is one of the few personal quantum computers.

http://www.dwavesys.com/en/dw_homepage.html