Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

How do You Count in Hexa-Binary?

Bloodsong Termagant
Manic Artist
Join date: 22 Jan 2007
Posts: 615
10-15-2007 09:02
heyas;

i understand bit-switches and bytes and the | and the & and bitwise operations and blah blah blah. what i don't actually know is how to count with these numbers. i mean, i've seen a few progressions on the wiki that i tried to copy... but obviously, i'm doing something wrong, because my grasshopper legs are not animating right with it.

so... how's it go? you know, these things: 0x001 0x002...? i need like 20 or 30 or so. and do the leading zeroes matter? is 0x01 different from 0x0001?

hey, i need to know! then i wont be stupid no more ;)
Lee Ponzu
What Would Steve Do?
Join date: 28 Jun 2006
Posts: 1,770
10-15-2007 09:18
1,2,3,4,5,6,7,8,9,a,b,c,d,e,f,10,11,12,13,14,15,16,17,18,19,1a,1b,1c,1d,1e,1f,20...

...9a,9b,9c,9d,9e,9f,a0...aa,ab,ac,ad,ae,af,b0...

leasing zeros don't matter.

binary goes

0,1,10,11,100,101,110,111,1000 ...

You should look at octal, too.
Meade Paravane
Hedgehog
Join date: 21 Nov 2006
Posts: 4,845
10-15-2007 09:23
ASCII charts are always good for binary/decimal/hex tables. Try http://en.wikipedia.org/wiki/Ascii .

See also: http://forums.secondlife.com/showthread.php?t=174208
_____________________
Tired of shouting clubs and lucky chairs? Vote for llParcelSay!!!
- Go here: http://jira.secondlife.com/browse/SVC-1224
- If you see "if you were logged in.." on the left, click it and log in
- Click the "Vote for it" link on the left
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
10-15-2007 17:57
it might help to realize that number systems use their base as a power

for example...

binary = base 2 (0-1)
2^0 = 1
2^1 = 10 (2 in decimal )
2^2 = 100 (4 in decimal )
notice how each power moves the place held by one

in hexadecimal (base 16 0-9+A-F) you get
16^0 = 1
16^1 = 10 (16 in decimal )
16^2 = 100 (256 in decimal )
16^3 = 1000 (4096 in decimal )
the last would be written as 0hx1000 ...leading spaces are unneeded and usually there to describe the max number that can go in that data size

that means for any number in hex (ex 3FE) the number =
3*16^2 + F*16^1 + E*16^0...
or
3*256 + 15*16 + 14 = 1022


why hex? because it's a square power of 2, so it can be shown easily in binary, also because it represents numbers in a smaller space than decimal, and is easier to convert back to binary (visually), and easier to read than binary... since 4 bits binary = 1 character hex, it's less of a pain to print =)

this is why you see %20 instead of a space in some urls... because spaces don't translate well (used to divide commands usually), the character code (8bits) for a space is the % sign + the characters number (20 in hex, 32 in decimal)...%21 is "A" for example
Sindy Tsure
Will script for shoes
Join date: 18 Sep 2006
Posts: 4,103
10-15-2007 19:12
Or, yet another way to say what everybody else is saying...

Think about a car odometer.. It's got a bunch of dials with the numbers 0 through 9 on them. As you move, the right-most dial counts upwards. When it gets all the way around, it goes back to 0 and the dial to its left moves up a notch. When that one goes past 9, it goes back to 0 and the one to its left moves up one. And so on and so on.

Counting in binary is the same thing but it only uses the numbers 0 and 1. You count in binary like this:
000
001
010
011
100
101
110
111

Hex or hexadecimal is again the same thing but it uses 0 through 9 and A through F. Why A through F? Because they're easy to remember - there's no special meaning to them. You start at 0 and count up to F. Once you get there and add one, you're at 10. Count from there up to FF and add one and you get 100..

Octal used to be used in computer stuff a lot but it's pretty dated now. Same as the others but you only get to use 0 through 7.

The leading 0x in hex numbers is just a way to make it clear which system you're using - the number 27 in decimal (0 through 9 is decimal) is a lot smaller than the number 27 in hexadecimal (and bigger than the one in octal). Usually it's a leading 0x for hex, a trailing b for binary (eg: 10b), a leading 0 for octal and nothing for decimal.
Bloodsong Termagant
Manic Artist
Join date: 22 Jan 2007
Posts: 615
10-17-2007 10:44
mmm...

thanks, but none of that answered my question. i understand all the theory etc etc. i just dont know the proper notation. i just need a list of the numbers, how to write them. in order.

so, i'll start.

0x0001
0x0002
0x0004
.
.
.
?
?
?



and is this the same, or is it different numbers?

0x01
0x02
0x04
.
.
.
_____________________
Why Johnny Can't Rotate:
http://forums.secondlife.com/showthread.php?t=94705
Meade Paravane
Hedgehog
Join date: 21 Nov 2006
Posts: 4,845
10-17-2007 10:48
Leading zeros (ones on the left) don't matter.. 0000000000001 is the same as 0001 is the same as 1, regardless of if you're talking decimal, hex or binary. They all mean "one".

A lot of people add them because it lines things up nicely and makes them easier to read.
_____________________
Tired of shouting clubs and lucky chairs? Vote for llParcelSay!!!
- Go here: http://jira.secondlife.com/browse/SVC-1224
- If you see "if you were logged in.." on the left, click it and log in
- Click the "Vote for it" link on the left
Lee Ponzu
What Would Steve Do?
Join date: 28 Jun 2006
Posts: 1,770
10-17-2007 17:12
comment two answers your original question...

1
2
3
4
5
6
7
8
9
a
b
c

etc etc etc
Nika Talaj
now you see her ...
Join date: 2 Jan 2007
Posts: 5,449
10-17-2007 18:09
From: Bloodsong Termagant
you know, these things: 0x001 0x002...? i need like 20 or 30 or so. and do the leading zeroes matter? is 0x01 different from 0x0001?
The only tricky part about the basic counting sequence is when you roll over into the next digit. The "numbers" are 0-F, so the rollover goes like:
0x000E
0x000F
0x0010
0x0011
...
0x001F
0x0020
etc.

Now, 0x01 does indicate something a little different than 0x0001. They both are equivalent to the number 1, but 0x01 is referring to a byte (8 bits) with the value 1. 0x0001 is referring to a 16-bit word with the value 1. This CAN be important when programming, particularly when using logic operations like AND and OR, or in other situations where the word length is important. Even arithmetic sometimes, when sign extension comes into play.
_____________________
.
:) To contact forum folks, join the inworld group "The Forum Cartel". New residents with questions about SL more than welcome! We has parties!

:) To contact forum scripters, join the inworld group "Scriptoratti" (thanks Void!). New scripter questions welcome!
Lyn Mimistrobell
(waiting)
Join date: 11 Jan 2007
Posts: 179
10-18-2007 04:05
If you're on a Windows computer, open up Calculator and in the menu View select Scientific. That will open up Hex/Dec/Oct/Bin conversions for you... Click the Dec radiobutton, enter e.g. 30 and click the Hex radio button. It will now say 1E (which is the hexadecimal representation for decimal 30). If you click the Bin radio button, it will show you 11110 (whic is the binary representation for decimal 30).

Void's explanation is a good one, and can help you learn to calculate them yourself. The same method applies to decimal, binary, hexadecimal and octal and any other system you could think of. Position 0 (right most) is 'scale' to the power of 0. Position 1 (left of 0) is 'scale" to the power of 1, etc. Scale in this case is 2 for binary, 8 for octal, 10 for decimal and 16 for hexadecimal.

If you don't care about the mechanism but just want to convert... use calculator :)
Kidd Krasner
Registered User
Join date: 1 Jan 2007
Posts: 1,938
10-18-2007 08:02
From: Bloodsong Termagant

thanks, but none of that answered my question. i understand all the theory etc etc. i just dont know the proper notation. i just need a list of the numbers, how to write them. in order.

Umm, whatever for? If you just need the numbers in a list, use a for loop.

The only justification I can think of is if you're trying to define your own bit masks.

From: someone

0x0001
0x0002
0x0004
...
and is this the same, or is it different numbers?

0x01
0x02
0x04
...

They're the same, at least as far as LSL is concerned, because there's only one integer type. Some other language could, conceivably, treat the first as 16-bit integers and the second as 8-bit integers, but they'd still have the same mathematical values.
Bloodsong Termagant
Manic Artist
Join date: 22 Jan 2007
Posts: 615
10-19-2007 08:00
heyas;

yes, i AM trying to define my own bit masks.

it is not 1 2 3, because 3 is 1+2. its 1 2 4.


the last thing i did was go like this:

0x001
0x002
0x004
0x008
0x016
0x032
0x064
0x128
.
.
.


but this is obviously fubar, because it totally failed to work right.


okay, maybe im asking the wrong question? what DO you call binary bit masks expressed in this hex format? and um, btw.... how do you write out the numbers in progression???

heck, do i even NEED this format? or can i go 1, 2, 4, 8, 16, 32, 64...????

ARGH!
Meade Paravane
Hedgehog
Join date: 21 Nov 2006
Posts: 4,845
10-19-2007 08:09
Hey, that's not counting!!

/me thinks you want...
0x0001
0x0002
0x0004
0x0008
0x0010
0x0020
0x0040
0x0080
0x0100
0x0200
0x0400
0x0800
0x1000
0x2000
0x4000
0x8000

To the compiler, the above is _exactly_ the same as this...
0x1
0x2
0x4
0x8
0x10
0x20
0x40
0x80
0x100
0x200
0x400
0x800
0x1000
0x2000
0x4000
0x8000

The top one is easier for _people_ to read, though. That's usually why people add the leading zeros.

edit: and yes, you could just use 1, 2, 4, 8, 16, 32, etc.. Again, it's _exactly_ the same as far as the compiler is concerned - it's just different human-readable ways to say the same numbers. The ones at the top of my post are still easier for you to read, though.

edit edit: and, if it helps visualize what's going on here, the binary version of the numbers above would be:

0000000000000001
0000000000000010
0000000000000100
0000000000001000

0000000000010000
0000000000100000
0000000001000000
0000000010000000

0000000100000000
0000001000000000
0000010000000000
0000100000000000

0001000000000000
0010000000000000
0100000000000000
1000000000000000
_____________________
Tired of shouting clubs and lucky chairs? Vote for llParcelSay!!!
- Go here: http://jira.secondlife.com/browse/SVC-1224
- If you see "if you were logged in.." on the left, click it and log in
- Click the "Vote for it" link on the left
Deanna Trollop
BZ Enterprises
Join date: 30 Jan 2006
Posts: 671
10-19-2007 08:19
If you only want exactly one "1" bit, in hex, use only 1, 2, 4 and 8:

0x001
0x002
0x004
0x008
0x010
0x020
0x040
0x080
[...]

Which, in binary, are:

0000 0000 0001
0000 0000 0010
0000 0000 0100
0000 0000 1000
0000 0001 0000
0000 0010 0000
0000 0100 0000
0000 1000 0000


Conversely, 0x016, 0x032, 0x064 and 0x128, respectively, are:

0000 0001 0110
0000 0011 0010
0000 0110 0100
0001 0010 1000

Keep in mind that 0-9 are equivalent in decimal and binary, hence 0x1 == (decimal)1, 0x2 == (decimal)2, etc. However, you continued to use the "powers of 2" progression, but using hexadecimal notation. (decimal)16 is 0x10, (decimal)32 is 0x20, etc. So just using decimal powers of 2 would work, but once you understand it, hexadecimal notation is easier to read, i.e. You should be able to quickly tell that 0x0400 has a 1 in the 11th bit from the right, whereas the decimal value is 1024, for which this isn't as obvious.
Lear Cale
wordy bugger
Join date: 22 Aug 2007
Posts: 3,569
10-19-2007 08:32
Good posts, folks.

BTW, it's called "hexadecimal", or "hex" for short.