Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-06-2004, 05:43 AM   PM User | #1
SpiritualStorms
Regular Coder

 
Join Date: Dec 2003
Location: America
Posts: 544
Thanks: 0
Thanked 0 Times in 0 Posts
SpiritualStorms is an unknown quantity at this point
How does the hexadecimal system work?

I have been thinking for a while as to how the 6 digit system for the hexidecimal works. I dont get how it is that one can get 256 colors from merely 6 digits. If i take a calculator, and i multiply 6 times 16, i get only 96 different potential variations, so how can that be the same as 256? I know theres 0 through 9, and from there, its like A through F for anything higher than 9. Thus, i know that #000000 is like pure for pure black. For white, its #ffffff. But i do not get from this, how it is that it can be 256 colors.

Can anyone lend a hand, or an explanation?
__________________
LovesWar
SpiritualStorms is offline   Reply With Quote
Old 07-06-2004, 05:48 AM   PM User | #2
Willy Duitt
Banned

 
Join Date: Sep 2003
Posts: 3,620
Thanks: 0
Thanked 0 Times in 0 Posts
Willy Duitt is an unknown quantity at this point
Your not very good at math are you?
Willy Duitt is offline   Reply With Quote
Old 07-06-2004, 05:54 AM   PM User | #3
SpiritualStorms
Regular Coder

 
Join Date: Dec 2003
Location: America
Posts: 544
Thanks: 0
Thanked 0 Times in 0 Posts
SpiritualStorms is an unknown quantity at this point
LOL............never been my greatest skill. I am a visual person, so i try to visualise concepts so that i may understand them. If i however multiply 16 times 16, then i get 256. Is that how its supposed to be?
__________________
LovesWar
SpiritualStorms is offline   Reply With Quote
Old 07-06-2004, 06:19 AM   PM User | #4
neofibril
Regular Coder

 
Join Date: Jun 2004
Location: underground
Posts: 186
Thanks: 0
Thanked 0 Times in 0 Posts
neofibril is an unknown quantity at this point
an exercise:

The Hexadecimal Number System
neofibril is offline   Reply With Quote
Old 07-07-2004, 03:49 AM   PM User | #5
SpiritualStorms
Regular Coder

 
Join Date: Dec 2003
Location: America
Posts: 544
Thanks: 0
Thanked 0 Times in 0 Posts
SpiritualStorms is an unknown quantity at this point
So is anyone gonna answer my question? Is it 16 times 16?
__________________
LovesWar
SpiritualStorms is offline   Reply With Quote
Old 07-07-2004, 05:49 AM   PM User | #6
JohnKrutsch
Regular Coder

 
Join Date: Jun 2002
Location: The Planet Earth Code Poet: True
Posts: 282
Thanks: 0
Thanked 1 Time in 1 Post
JohnKrutsch is an unknown quantity at this point
They all ready did. The link that neofibril supplied more than adequately explained how The Hexadecimal Number System works.

And yes 16*16=256
JohnKrutsch is offline   Reply With Quote
Old 07-07-2004, 06:06 AM   PM User | #7
SpiritualStorms
Regular Coder

 
Join Date: Dec 2003
Location: America
Posts: 544
Thanks: 0
Thanked 0 Times in 0 Posts
SpiritualStorms is an unknown quantity at this point
I didnt really understand the excercises. I get the idea of how the letters represent higher digits than 9, but over, and beyond that, i didnt get a friggin thing. I need things broken down before i get things.
__________________
LovesWar
SpiritualStorms is offline   Reply With Quote
Old 07-07-2004, 07:15 AM   PM User | #8
Garadon
Regular Coder

 
Join Date: Jul 2002
Posts: 698
Thanks: 0
Thanked 0 Times in 0 Posts
Garadon is an unknown quantity at this point
the hexadecimal system works just like the normal 10 base system.
the first hex on the left of a number is 1's so a number with only 1 digit can be between 0 and 15(f):0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f
the next digits is then increased for every time you have 16 or more of the digit before it so 16 would be :16=#10,17=#11,18=#12.

a color code hex number is infact not 1 number but 3hex numbers.
2 digits for red
2 digits for green
2 digits for blue

each number can be between 0-255. this can be calculated by saying that you can store 16 sixteen times with to digits 16x16=256 but since 1 number i zero the range is 0-255.
each of the 3 numbers(red,green,blue) indicates how much of that color to put in the final color. And as standard it was decided in the way way past that a 0 of all three(#00{red}00{green}00{blue} should black and a full of all 3(#ff{red}ff{green}ff{blue}should be white.
And contrary to what you said this system allows for 256^3 different colors not just 256 colors.

Hope that helped.
Garadon is offline   Reply With Quote
Old 07-07-2004, 11:53 AM   PM User | #9
SpiritualStorms
Regular Coder

 
Join Date: Dec 2003
Location: America
Posts: 544
Thanks: 0
Thanked 0 Times in 0 Posts
SpiritualStorms is an unknown quantity at this point
See what kills me is the idea of a set. I know that 10 is really 16, since f is 15. In this sense, the one is for a single set, while, the zero is for nothing left over.

This is ok up until i get to something like 26. If i say, its 2 sets, plus a 6, then i would be inclined to think, ok, thats 30 plus 6, which is 36, but that isnt correct either. Hence, from my perspective, there isnt an easy way of using a formula in my head by which to easily figure out how to go from regular math notation to hexadecimal notation.

For something like FF, i know the answer is 240 plus 15, since the first letter means 15 times 16, which gives us 240. The second F means 15, so when you add 240 plus 15, you get 255. But i dont see how to apply a consistant formula all accross the board. This is why i dont fully get it.

How do i break something like, 24 for red, 26 for green, and 24 for blue. How do i break down into their hexadecimal equivalents? In other words, how do i do it automatically in my head without having to like count with my toes. If i write everything down, then yea, i could figure out. But i dont always want to have to write things down.

At any rate, if in human terms the number is 24, i add 6 to get 30, which would be the hexadecimal equivalent. But if the hexadecimal is like lets 56, then i subtract 6, and i get 50, for the human notation version of the number.

Somehow, anything after F, you have to add a 6 to get an idea of the hexadecimal equivalency. 14 then is like 20 since i have added a 6. But how do i figure out something like 35 in hexadecimal notation? I subtract, right? and i subtract 6 since, the differences between regular sets, and hexadecimal sets is 6. If you go from human notation to hexadecimal, you add a 6, but if you go from hexadecimal to human, you subtract a 6.

But how do i do an easy translation of something like BB? Or ED? What B= 11, but how then do i understand the 11? If i had to just do math, i would probably be inclined to just ad 6, but that isnt correct since the 11 here means 11 sets of something, which is 16. This being the case, i know then that i multiply 11 sets times 16 to get 176; and from here, we add another 11 for the second b to get the final answer of 187?

I am not sure i am phrasing my problem. i know that the second digit generally presents a set, hence, 10 means a whole set of 15---if the 10 here in the hex system, and not in the human system. In the human system, 10 is anything over 9, but in hex, its anything after F, which is 16. But supposing i was already in the hex system: how would i do 255? Do i simply subtract 6 to get 249? Is this correct? 249 is the human version of the hex system of 255?
__________________
LovesWar

Last edited by SpiritualStorms; 07-07-2004 at 12:54 PM..
SpiritualStorms is offline   Reply With Quote
Old 07-07-2004, 01:21 PM   PM User | #10
nolachrymose
Regular Coder

 
Join Date: Jun 2002
Posts: 338
Thanks: 0
Thanked 0 Times in 0 Posts
nolachrymose is an unknown quantity at this point
It's all about place values. But just to preface, it doesn't make sense to call the decimal system the "human" system. Hexadecimal is just as much a human base as decimal.

When you have a number in decimal, say, 456, each digit represents a place value. Here, "6" is the "units" digit (1), so you multiply 6*1. Then, "5" is the "tens" digit (10), so you multiply 5*10. Then, "4" is the hundreds digit (100), so you multiply 4*100. The sum of these products is equal to the number itself.

The reason we do this is because each digit is "mapped" to a power of ten, starting from 0. The "6" is in the place value 10^0, or 1. The "5" is in the place value 10^1, or 10. The "4" is in the place value 10^2, or 100.

What does this mean in terms of hexadecimal, though?

When you use a different base system, it's very simple to convert to decimal. All you do is switch the base in the above example to the base you are using (in your case, 16). So, for instance, if we have the number 255 in hexadecimal, the conversion process to decimal would be this:

5 * 16^0 = 5*1 = 5
5 * 16^1 = 5*16 = 80
2 * 16^2 = 2*256 = 512

Then, we take the sum (5 + 80 + 512) and we get 597. That is the decimal value of the hex. number 255.

Hope that helps!

Happy coding!
nolachrymose is offline   Reply With Quote
Old 07-07-2004, 01:38 PM   PM User | #11
dumpfi
Regular Coder

 
Join Date: Jun 2004
Posts: 565
Thanks: 0
Thanked 18 Times in 18 Posts
dumpfi will become famous soon enough
Quote:
Originally Posted by SpiritualStorms
This is ok up until i get to something like 26. If i say, its 2 sets, plus a 6, then i would be inclined to think, ok, thats 30 plus 6, which is 36, but that isnt correct either.
26 => 2 full sets + 6 left over => 2 * 16 + 6 = 38

Quote:
How do i break something like, 24 for red, 26 for green, and 24 for blue. How do i break down into their hexadecimal equivalents? In other words, how do i do it automatically in my head without having to like count with my toes. If i write everything down, then yea, i could figure out. But i dont always want to have to write things down.
Use a calculator, if you aren't good enough in multiplication and addition.

Quote:
But if the hexadecimal is like lets 56, then i subtract 6, and i get 50, for the human notation version of the number.
(hex) 56 => 5 full sets + 6 left over => (dec) 5 * 16 + 6 = 86
(dec) 86 => FLOOR(86 / 16) full sets + 86 % 16 left over => (hex) 5 * 10 + 6 = 56

Quote:
But how do i do an easy translation of something like BB? Or ED? What B= 11, but how then do i understand the 11? If i had to just do math, i would probably be inclined to just ad 6, but that isnt correct since the 11 here means 11 sets of something, which is 16. This being the case, i know then that i multiply 11 sets times 16 to get 176; and from here, we add another 11 for the second b to get the final answer of 187?
BB => 11 full sets + 11 left over => 11 * 16 + 11 = 187
ED => 14 full sets + 13 left over => 14 * 16 + 13 = 237

Quote:
But supposing i was already in the hex system: how would i do 255? Do i simply subtract 6 to get 249? Is this correct? 249 is the human version of the hex system of 255?
255 => 2 full sets of full sets + 5 full sets + 5 left over => 2 * 16 * 16 + 5 * 16 + 5 = 597

dumpfi

Last edited by dumpfi; 07-07-2004 at 01:56 PM..
dumpfi is offline   Reply With Quote
Old 07-07-2004, 02:16 PM   PM User | #12
trib4lmaniac
Regular Coder

 
trib4lmaniac's Avatar
 
Join Date: Feb 2004
Location: Cornwall, UK
Posts: 535
Thanks: 0
Thanked 0 Times in 0 Posts
trib4lmaniac is an unknown quantity at this point
Quote:
Originally Posted by SpiritualStorms
If i take a calculator, and i multiply 6 times 16, i get only 96 different potential variations
lol... that's a far cry from the 16 and a half million combinations available!
trib4lmaniac is offline   Reply With Quote
Old 07-07-2004, 02:21 PM   PM User | #13
dumpfi
Regular Coder

 
Join Date: Jun 2004
Posts: 565
Thanks: 0
Thanked 18 Times in 18 Posts
dumpfi will become famous soon enough
Quote:
Originally Posted by trib4lmaniac
lol... that's a far cry from the 16 and a half million combinations available!
Actually, 6 times 16 is 96.

Next time he should try 16^6.

dumpfi
dumpfi is offline   Reply With Quote
Old 07-07-2004, 02:46 PM   PM User | #14
trib4lmaniac
Regular Coder

 
trib4lmaniac's Avatar
 
Join Date: Feb 2004
Location: Cornwall, UK
Posts: 535
Thanks: 0
Thanked 0 Times in 0 Posts
trib4lmaniac is an unknown quantity at this point
You know what I mean
trib4lmaniac is offline   Reply With Quote
Old 07-08-2004, 12:35 AM   PM User | #15
SpiritualStorms
Regular Coder

 
Join Date: Dec 2003
Location: America
Posts: 544
Thanks: 0
Thanked 0 Times in 0 Posts
SpiritualStorms is an unknown quantity at this point
I realise that. All languages are human made, hence human based. However, because some times one needs to create distinctions for effective communication, i chose a set of terms that would contrast the 2 for easier references.

Quote:
from: nolachrymose,
It's all about place values. But just to preface, it doesn't make sense to call the decimal system the "human" system. Hexadecimal is just as much a human base as decimal.
It helps some times when one uses gimmick like thought structures to differenciate one thought from another.
__________________
LovesWar
SpiritualStorms is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:21 PM.


Advertisement
Log in to turn off these ads.