Binary and Hexadecimal; my views
Disclaimer; for those that know a lot about these numerical systems, you likely won't gain a lot from this. Though you are, of course, very welcome to offer insight.
Binary and hexadecimal numerical systems are, naturally, fairly common in technology. Where hex is often used in RGB colour (CSS, as an example) and binary has any number of uses though namely for the hardware side of things, these numerical systems I found to be a little alien when I first encountered them.
Strangely, I now find binary rather simple. When I first began to understand it, my view was that it functioned in, well, a very binary fashion.
Where you can see binary numbers as just that, you can also see them as "switches", Boolean values and the like. Take the following as an example;
00101001
Of course, it simply appears as a string of numbers but if you regard it in a different light, you can also see it as;
off off on off on off off on
This is how I learned it myself. Whilst it's by no means the most practical method (especially when you get into calculations), I found it the most digestible. In using this, you can address each position using these terms. Each position (from right to left) represents a number, incrementing indexes of 2; 2^0, 2^1, 2^2, etc. A simple breakdown would look like;
128 64 32 16 8 4 2 1
If we compare this with our binary figures, we have; 1, 8 and 32 as "on". In other words;
00101001
The first, fourth and sixth positions are marked by a number 1, so 2^0, 2^3 and 2^5. The zeroes we can then simply ignore and discard.
The solution is simple addition; 1 + 8 + 32 = 41.
This solution will work for practically any number;
01010101 = 2^0 + 2^2 + 2^4 + 2^6 = 85
00001111 = 2^0 + 2^1 + 2^2 + 2^3 = 15
What's more is that this logic can then be used to immediately work out whether a number is odd or not. Since all numbers are multiples of 2, they will always be even unless the only number which is not a 2, i.e. the first number, is a 1. So we know immediately that 00100101, 11111111, 11011101, etc., are all odd where 01100110, 11110000, 10101010, etc., are all even.
We can reverse this to create a binary number out of any decimal number. Let's say 33. As we know that 32 is already within our range of numbers on our "switches", we simply have to place that number in the "on" position. We then know that we simply need the 1 from the first position to be our final number, so our solution is; 2^5 and 2^0, this gives us (from right to left) the first and sixth positions, so; 00100001 = 33.
Perhaps this isn't the most efficient method, but this is the way I personally learned.
Hexadecimal is a fairly tricky numerical system. The name, as you may know, simply refers to the fact that the system has 16 numbers per unit, hexa referring to the six and deca referring to the ten.
Hexadecimal uses letters to make up for these extra numbers; A through to F in alphabetical order. Where the decimal system has ten numbers to every unit, this system has 16; for example, singles in a decimal number such as 16 would refer to the 6. If that single number were to increase beyond 9, for example if we were to add 4 to 16, the "tens" number would increase by 1, giving 20.
This is different in hexadecimal; take the following "number";
A6
What does this number actually mean? Well, in the same way that 16 has singles and tens, this number is similar. Only, this number is very much different in other ways.
As hexadecimal, ten is not represented by 10. Confusingly, this number is actually 16 in decimal systems. Why?
In hexadecimal, 9 + 1 is A. In other words, A = 10 in decimal systems. So, B is 11, C is 12, D is 13, E is 14 and F is 15. What happens when we add one to F?
F + 1 = 10 (in hexadecimal) = 16 (in decimal).
In using this logic, what is our example in decimal form?
As we now know, A is equivalent to 10. In using this, the first position is 10 with the second being 1.
How do we use this to calculate it?
In the same way that 90 is mine lots of ten, or 9 * 10, A is equal to 10 lots of 16, or 10 * 16. In this sense, we can calculate that A * 16 = 160. All we need do then is add the 1. So;
A1 = 161 in decimal form.
As it is now past three in the morning, it's quite possible I've made several mistakes. If you spot them, please do point them out.
I've tried to address these calculations as best I can. These are the ways I learned, along with the ways I now understand them. I've tried to keep it simple without being too condescending or patronising. I'm clearly no expert on it. It was just a thought I had recently and I wondered if people may like reading about it, or discussing it, or both.
Of course, I'm now open to criticism and welcome it.
Thanks.
Thanks for that.
I've never found any practical use so far for binary and hex, though it's interesting nonetheless. I've noticed that some numbers in the Windows Registry seem to be in hex, and have wondered why the letter x sometimes appears in them, eg 0x000C15. This is equivalent to 3093, but I'm not sure what the x adds to this.
_________________
On a mountain range
I'm Doctor Strange
I've never found any practical use so far for binary and hex, though it's interesting nonetheless. I've noticed that some numbers in the Windows Registry seem to be in hex, and have wondered why the letter x sometimes appears in them, eg 0x000C15. This is equivalent to 3093, but I'm not sure what the x adds to this.
I think 0x is often used in computing simply to denote hexadecimal numbers. When using colours, similar in a sense to your example, you'll usually see them in clusters of six, so the number will be registered as 0x000000, where you can basically plug any number following the x. The technical details, I'm not personally sure of. It is something I've come across in assembly language but what the 0x "does" is not something I understand myself. My guess is that it's simply an operator, like how you would write "-" in front of a number to give a negative, you would write "0x" to give hexadecimal.
For curiosities sake, C15 is equivalent to 3093, so the 0x doesn't actually change anything. And of course the maths is; (16 * 16) * 12 + 21 = 3093 (I hope I did that right).
As for uses, I'm still stuck on that myself. There are probably a lot in computer science but this, like in your example, is more than likely on the particularly technical side, and in assembly language as I mentioned before which is more detailed to what you might call an atomic level than most common languages (Python, Java, C, etc.)
Maybe I'm just weird, but I tend to convert hex into binary, rather than dec...but I suppose it depends on what I'm doing. Sometimes it's nice to get at those bits. Sometimes data is stored in ways that aren't immediately obvious.
For example, if you had something like 6F, that would convert to 01101111 in binary.
Let's say they stored that as 01-101111, so that the 01 (two bits) was one set of information, and the rest was for something else. That's not obvious when you're just looking at the hex, but the program knows what it's looking for.
If you mean the technical details of the colors, it's usually 0xRRGGBB. Some color formats give extra bits to certain color channels, though.
Nope. As far as I know, it's human language, not machine language, so it's just there to let the reader know that it's in hex.
Basically, yes. In a lot of programming, it's very helpful to know binary and hex, especially if you need to program at a low level to really cram a lot of processing into a little bit of hardware. Most programmers these days are very wasteful and inefficient, it always amazes me when people are able to do incredible things with outdated machines.
I dabble in ROM hacking now and then, and it's nearly impossible to do any sort of reverse-engineering without knowing basic hex and binary.
_________________
he had a lot to say, he had a lot of nothing to say
we'll miss him
Most converters I think are automatically set to convert to binary. I'm guessing this is because binary is a more common system in computing than simple decimal numbers.
For example, if you had something like 6F, that would convert to 01101111 in binary.
Let's say they stored that as 01-101111, so that the 01 (two bits) was one set of information, and the rest was for something else. That's not obvious when you're just looking at the hex, but the program knows what it's looking for.
If you mean the technical details of the colors, it's usually 0xRRGGBB. Some color formats give extra bits to certain color channels, though.
That's the way I understood it as well, but I always just assumed it was more complicated than that. Maybe it isn't then.
Nope. As far as I know, it's human language, not machine language, so it's just there to let the reader know that it's in hex.
That's the way I personally see it. I don't know much beyond it simply signifying hex numbers but maybe that's all it's used for; user readability.
Basically, yes. In a lot of programming, it's very helpful to know binary and hex, especially if you need to program at a low level to really cram a lot of processing into a little bit of hardware. Most programmers these days are very wasteful and inefficient, it always amazes me when people are able to do incredible things with outdated machines.
This is something I hope to improve on in the near future. When I started, I was fairly useless at programming. I've definitely improved but have a long way to go. I've barely looked at low level programming yet.
I dabble in ROM hacking now and then, and it's nearly impossible to do any sort of reverse-engineering without knowing basic hex and binary.
All kinds of hacking is interesting to me, but I still have a long way to go before I can really delve into the more technical specifics. I'm hoping to install Kali Linux soon for some pen testing and maybe pick up some ideas on the more general details, then hopefully I'll end up studying hardware hacking at the lowest level. This is what I find most interesting, it's also what I personally find most difficult.
.
Yes, that was pretty much the original purpose. Because 16 is the fourth power of two, four bits (a nibble) is exactly equivalent to one hexadecimal digit, so it's a very compact and less error-prone way to easily write down a series of bits. It doesn't take too long to memorise all 16 bit combinations, so you can go hex<->binary much more quickly than converting to decimal.
Even if you don't use hex/binary in your code, knowing about the number bases can be helpful. For example, there is no exact binary equivalent to one tenth (0.1) or many other decimals. In the same way that decimal can't exactly represent one third (0.333... recurring forever), one tenth recurs forever in binary (0.000110011001100....) so, no matter how many bits you have, there's always a slight rounding error. This can make maths with decimal numbers do slightly unexpected things sometimes, for example, ten times a tenth might not actually equal one because the numbers are translated to binary and back again for the calculation.
Every string of decimal digits is also a valid hexadecimal number, so yes, "0x" is used as a sigil simply to indicate that a number is in hexadecimal. You quite often see "0b" for binary numbers, too, for the same reason. There are, and have been, programming languages that use different sigils, such as punctuation characters, but "0x" is by far the most common. The leading "0" means that the computer only has to look at the first character to know that it is a number.
_________________
When you are fighting an invisible monster, first throw a bucket of paint over it.
It's also good to know where the bits are, those are used for all kinds of things. A lot of games use them for things like simple inventories, or for setting gameplay options.
bit 1 might = weapons respawn;
bit 2 = friendly fire;
bit 4 = gore enabled;
etc.
So a flag of 3 would mean weapons respawn, friendly fire is enabled, but gore is disabled.
_________________
he had a lot to say, he had a lot of nothing to say
we'll miss him
It's also good to know where the bits are, those are used for all kinds of things. A lot of games use them for things like simple inventories, or for setting gameplay options.
bit 1 might = weapons respawn;
bit 2 = friendly fire;
bit 4 = gore enabled;
etc.
So a flag of 3 would mean weapons respawn, friendly fire is enabled, but gore is disabled.
Lotsa misinformation so far.
Everything in computing is represented by either an on-state (a '1') or an off-state (a '0'). These states are represented by binary digits (or 'bits'), either a 0 or a 1. Since there are only two states in a binary system, it is necessary to represent numerical values by stringing two or more bits together. Thus, two bits represent the decimal values of 0 through 3, three bits represent the decimal values of 0 through 7, four bits represent the decimal values of 0 through 15, and so forth.
Note that the maximum decimal value of any string of bits of 'n' bits in length is equal to (2^n)-1, if the minimum decimal value is offset to zero, which most computer systems are.
Resolution is a term found in computing, as well. If you have a 16-bit registry of hues from pure red to pure violet, you will have a resolution of 2^16 or 65536 hues. But what if you need a hue that is midway between &b0000011011101110 and &b0000011011101111? If your system is maxed-out at 16 bits, then you're out of luck; but if your system is expandable, then you can redefine your color palette to utilize the maximum resolution of your system. This will not be a continuous spectrum, but if you are running a 32-bit system, then you have a resolution of 2^32 or 4,294,967,296 hues!
Note: No system based on discrete numerical values (digits) can possibly have infinite resolution, unless it uses an infinite number of digits. Thus, 'digital' (discrete) is not 'analog' (continuous), and vice-versa.
Now, about those terms 'binary', 'octal', 'decimal', and 'hexadecimal'. They are nothing more than different ways to represent the same numerical values. Thus, '&b1101', '&o16', '&d14', and '&hE' all represent the same numerical value! Note that decimal values are usually assumed when there is no '&' followed by a letter preceding the numerical value.
By the way, our binary examples from the paragraph on hue have the following equivalencies:
&b0000011011101110
&o3346
&d1774
&h06EE
... and ...
&b0000011011101111
&o3347
&d1775
&h06EF
Hexadecimal is a specific case, in that it not only includes the numerical digits 0 through 9, but the alphabet characters A through F. Thus, &hA = 10, &hB = 11, &hC = 12, &hD = 13, &hE = 14, and &hF = 15.
_________________
Fnord, the Metasyntactic Variable -- Keeping it real
since '57 by explaining the obvious to the oblivious!
I understand that binary is useful for memory allocation, logic circuits and so forth. I've never quite appreciated why hexadecimals should be considered useful, though I agree that they're good fun!
_________________
L'enfer c'est les autres.
- Sartre
The mass of men lead lives of quiet desperation.
- Henry David Thoreau
Das Glück gehört denen, die sich selbst genügen. Denn alle äußeren Quellen des Glückes und Genusses sind, ihrer Natur nach, höchst unsicher, misslich, vergänglich und dem Zufall unterworfen.
- Arthur Schopenhauer
Mona Pereth
Sea Gull
Joined: 11 Sep 2018
Age: 60
Gender: Female
Posts: 246
Location: New York City (Queens)
Some examples:
1) RGB color codes. Every color on your computer screen consists of some combination of red, green, or blue. Each color is specified by three bytes, the first byte indicating the amount of red light, the second byte indicating the amount of green light, and the third byte indicating the amount of blue light. A byte is eight bits (binary digits). So, for example, brightest yellow would be represented in binary as follows:
11111111 11111111 00000000
or, more concisely, in hexadecimal:
FFFF00
2) Java and some other programming languages are written in ASCII text files, which means they can contain any English-language character. But what if you want your program to generate non-English text? The world's many major languages can be accommodated using Unicode, a much bigger character set than ASCII. So, in a Java program, if you want to specify a non-ASCII character, you can use the hexadecimal representation of the character's Unicode value.
Mona Pereth
Sea Gull
Joined: 11 Sep 2018
Age: 60
Gender: Female
Posts: 246
Location: New York City (Queens)
Hexadecimal is commonly used as an abbreviation for binary. Because 16 is 2 to the 4th power, each hexadecimal digit corresponds to a group of 4 binary digits (bits).
If, for whatever reason, you had to use a specific binary value in a program, which of the following could you type more easily and with less chance of error?
1011 0010 1001 1100
or
B29C
For most people, the latter would be easier and less error-prone.
Hexadecimal is commonly used as an abbreviation for binary. Because 16 is 2 to the 4th power, each hexadecimal digit corresponds to a group of 4 binary digits (bits).
If, for whatever reason, you had to use a specific binary value in a program, which of the following could you type more easily and with less chance of error?
1011 0010 1001 1100
or
B29C
For most people, the latter would be easier and less error-prone.
I didn't think of that.
_________________
L'enfer c'est les autres.
- Sartre
The mass of men lead lives of quiet desperation.
- Henry David Thoreau
Das Glück gehört denen, die sich selbst genügen. Denn alle äußeren Quellen des Glückes und Genusses sind, ihrer Natur nach, höchst unsicher, misslich, vergänglich und dem Zufall unterworfen.
- Arthur Schopenhauer
Similar Topics | |
---|---|
binary |
08 Oct 2008, 1:44 am |
Non-Binary? |
05 Sep 2016, 8:14 am |
Is there any other non-binary people here? |
18 Dec 2018, 12:08 am |
Education Binary |
20 Apr 2014, 1:47 pm |