What is $FFFF ?

Blitz3D Forums/Blitz3D Beginners Area/What is $FFFF ?

RiverRatt(Posted 2006) [#1]
Does anyone know where I can find more information about the
keys $A through $F. Are these used for binary math?
I can't figure out how they multiply by adding a letter.
example... $F = 15 , $FF = 255 , $FFF = 4095, but how
$F*$F <> 255
$F*$F*$F <> 4095
So how do they step?

Thanks for any help.


kragoth74(Posted 2006) [#2]
This is not binary math, it's hexadecimal math ;-) This means that we use 16 "digits". Instead of counting from 0 to 9, we count from 0 to 15, using letters for digits greater than 9.

So: A = 10, B = 11, C = 12, D = 13, E = 14, F = 15

Going from right to left, multiply the second digit by 16, the third by 256 (16 * 16), the fourth by 4096 (16 * 16 * 16) and so on...

So for example:

$ABCD = ($A * 4096) + ($B * 256) + ($C * 16) + $D = (10 * 4096) + (11 * 256) + (12 * 16) + 13 = 43981

Well, at least I can understand myself ;-). Hope this helps. Or you can google for "hex maths" ;-)


Warren(Posted 2006) [#3]
Google for "hexadecimal notation"


Adam Novagen(Posted 2006) [#4]
This is not binary math, it's hexadecimal math ;-) This means that we use 16 "digits".

Hooray, someone who knows Hexadecimal! I thought I was the only person!

On the subject of Binary, I love this quote:

"There are only 10 types of people in this world. Those who understand Binary, and those who don't."


Mr Snidesmin(Posted 2006) [#5]
As soon as you start messing with colors or using the readpixel writepixel functions you will learn everything there is to know about hexadecimals very quickly! :O)


LineOf7s(Posted 2006) [#6]
Hooray, someone who knows Hexadecimal! I thought I was the only person!


???

You need to get out more. Or at least out with more geeks.


Sir Gak(Posted 2006) [#7]
Hey, I understand hex too! LOL!

Adam, I love that quote!

"There are only 10 types of people in this world. Those who understand Binary, and those who don't."


xlsior(Posted 2006) [#8]
"There are only 10 types of people in this world. Those who understand Binary, and those who don't."


There's also its counterpart:

"There are only 11 types of people in this world. Those who understand Binary, and those who don't."


IPete2(Posted 2006) [#9]
There's also

"There are only 13 types of people in this world. Those who understand Binary, and those who don't. Er what's
Binary?

IPete2.


Mr Snidesmin(Posted 2006) [#10]
Yes, but remember if you like bees:

DEAD+BEE = 1+BAD+DEED

Bees make HEX-agonal nests! :O)


Adam Novagen(Posted 2006) [#11]
IPete2: Binary is a number system based around two digits: 0 and 1. These digits, on their own, are integral to computers: it's how they "think." 1 represents on, true, yes, etc, and 0 represents off, false, no, and so on. Believe it or not, these two numbers are what allow computers to perform complex mathematical functions such as rendering 3D graphics. Long live technology!


big10p(Posted 2006) [#12]
Er, I think IPete2 may just have been joking! ;)


Amanda Dearheart(Posted 2006) [#13]
I know hex.

I understand

There are only 10 types of people...


but whats behind

There are only 11 types of people...




xlsior(Posted 2006) [#14]
But what's behind 'There are only 11 types of people...


that would be those who don't understand binary. :-?


LineOf7s(Posted 2006) [#15]
There are only two types of people: Those who understand jokes about binary, and those who do not. :o)


RiverRatt(Posted 2006) [#16]
There is only 2 people in the world, Those who know what $FFFF means and those who don't give a $FFFF.


RiverRatt(Posted 2006) [#17]
Well I am both, but I still don't get how you can just plug the sequince rgb=ReadPixelFast(x,y) And $FFFFFF.
Not to mention the part about putting And after a statement, I thought that it was for conditional checks you know like
If $FFFF and (binary <> Question) then ect you know the rest.
I know binary. I saw it on TV once. You got eggs that fill containers (shaped like eggs) and each container holds a byte (and salt and pepper).


JazzieB(Posted 2006) [#18]
There's two versions of And in Blitz. The logical one that is typically used in If..Then statements (which you talk about), and also the bitwise version that is used in maths (such as in ReadPixel, etc).

The problem with Blitz3D is that they both look the same and Blitz3D decides which to use depending on the context in which it is used. However, the thing to remember is that even in those If..Then statements is that each condition is evaluated to True or False anyway (1 or 0) so a bitwise check is ultimately done to determine whether the condition has been met.

Most other languages actually make a distinction between the two to make it clearer what you want. For example, BlitzMax has And for logical operations and & for the bitwise version.


Mr Snidesmin(Posted 2006) [#19]
Don't people do truth tables for logic gates at school anymore?

How you can not understand a bitwise AND operation and still program I don't know. . . :O)


big10p(Posted 2006) [#20]
JazzieB: I'm pretty sure Blitz3D only supports And as a bitwise operator. To use it as a logical operator, you have to something like:

If (val1 <> 0) And (val2 <> 0) Then ...

Haven't used B3D in ages so I may be off, here - bit rusty. :)


Mr Snidesmin(Posted 2006) [#21]

Blitz3D only supports And as a bitwise operator.
...
If (val1 <> 0) And (val2 <> 0) Then ...


Hmmm. interesting. . . but it makes sense because there's no way for a compiler to tell if you want bitwise or normal boolean based on context (because there is no boolean data type)

I also assumed Blitz3d evaluates any non-zero result as true.

If both of these are true then a lot of my code may be iffy.

I guess I may have been lucky that my code tends not to generate (except when I intend to perform a bitwise) occasions where 1010 (10) is being anded with 0101 (5)
etc, because I would have gotten false when I would have expected True!

I'm not at a PC with blitz installed right now, but I will check into this tonight to be sure.


Mr Snidesmin(Posted 2006) [#22]
I'm not at a PC with blitz installed right now


Reminds me, I wish Blitz would publish the Blitz3d language reference as well as the command reference section in the online manual.


big10p(Posted 2006) [#23]
If both of these are true then a lot of my code may be iffy.

I guess I may have been lucky that my code tends not to generate (except when I intend to perform a bitwise) occasions where 1010 (10) is being anded with 0101 (5)
etc, because I would have gotten false when I would have expected True!

Yep. If you're not aware of this, it can lead to some seemingly invisible bugs in your code logic. Nasty. :)


Mr Snidesmin(Posted 2006) [#24]
Darn. . . now I need to check a few million lines of code!

Though, so far I don't think I've experienced this because whenever I'm intending to use a boolean I always use just values of 1 and 0, or the keywords True and False (which are the same thing.)

I guess it's REALLY important to know this though - everyone take heed! :O)


JazzieB(Posted 2006) [#25]
JazzieB: I'm pretty sure Blitz3D only supports And as a bitwise operator. To use it as a logical operator, you have to something like:

If (val1 <> 0) And (val2 <> 0) Then ...

Haven't used B3D in ages so I may be off, here - bit rusty. :)

Possibly, but then all conditions are evaluated to True (1) or False (0) anyway, so ultimately it's all bitwise. I've not found brackets necessary unless you have some complicated conditions to be met. In your example, if both val1 and val2 were non zero, Blitz would be doing a bitwise 1 and 1, which is 1 (True). If val1 was 0, then it would be 0 and 1, which is 0 (False).

I also assumed Blitz3d evaluates any non-zero result as true.
True. And this also includes negative numbers. Only 0 is False.


octothorpe(Posted 2006) [#26]
example... $F = 15 , $FF = 255 , $FFF = 4095, but how
$F*$F <> 255


Last time I checked, 15 * 15 == 225, not 255. Kinda like how 9 * 9 == 81, not 99.

rgb=ReadPixelFast(x,y) And $FFFFFF


When you And, you get only the bits back that you have selected. The above code gets rid of anything not in the lowest 24 bits - presumably the alpha channel in $FF000000.


Mr Snidesmin(Posted 2006) [#27]

In your example, if both val1 and val2 were non zero, Blitz would be doing a bitwise 1 and 1, which is 1 (True)




Try this:

val1% = 10
val2% = 5

Print ((val1) And (val2))
Print ((val1<>0) And (val2<>0))

WaitKey
End


and you'll see the difference!


Mr Snidesmin(Posted 2006) [#28]
I was just wondering which of ( <>, And ) were evaluated first by default.

The following expression evaluates to 0:

(1<>2 And 2)

Therefore <> must evaluate before And because (2 And 2) = 2 so the expression would be equivalent to 1<>2 if and evaluated first and would give the value True (1).

This means that Jazzieb is right in that you don't need the brackets in
If (val1 <> 0) And (val2 <> 0) Then


But you do need to still include the <>0 parts to be sure to get a single bit boolean And between val1 and val2.


big10p(Posted 2006) [#29]
I included the brackets for clarity. ;)


Mr Snidesmin(Posted 2006) [#30]
oh, btw I have probably steered this way off topic - sorry!

If you are familiar with binary but not hex, the easiest way to think of hex is as a simple encoding of a binary number where:


Hex = Binary
0 = 0000
1 = 0001
2 = 0010
3 = 0011
4 = 0100
5 = 0101
6 = 0110
7 = 0111
8 = 1000
9 = 1001
A = 1010
B = 1011
C = 1100
D = 1101
E = 1110
F = 1111


you can therefore easily convert from one to the other.

For example,

A7 in hex is the same as 1010 0111 in binary.


Mr Snidesmin(Posted 2006) [#31]
I included the brackets for clarity.


Good idea big10p! It's generally best to include brackets if there is any doubt because then the code is easier to understand for people that aren't familiar with the conventions of the specific language.

I try to use brackets often because I program in quite a few different languages and I can never remember (nor do I want to even know or think about) the priority of operations in a given language.

Having said that, generally most languages use the same or similar priorities but there will always be that exception that kills you!


JazzieB(Posted 2006) [#32]
Try this:


val1% = 10
val2% = 5

Print ((val1) And (val2))
Print ((val1<>0) And (val2<>0))

WaitKey
End


and you'll see the difference!


I already know the difference, I'm no newbie! The point I was trying to get across was that conditions are evaluated to True (1) or False (0), so bitwsie ANDing, ORing and whatnot are happening in the background to determine if a condition is true or not.

The first Print statement only has the values of those variables, so a bitwise And is done. The second you are comparing them with other values first, giving an outcome of either 1 or 0 for each, but a bitwise And is still done after getting those results - it just looks logical.


D4NM4N(Posted 2006) [#33]
Base 10(decimal) is 0123456789
Base 16(hexadecimal) is 0123456789ABCDF

In hex, one character= the less herd of NYBBLE.

Ther are 4 bits in a nibble and 2 nibbles in a BYTE(or 8 bits)

a collection of bytes is called a WORD

FF is an 8 bit word (2 nibbles or 1 byte) which is (16x16=256)-1(for zero)=255 (256 possible numbers inc. 0)

FFFF is a 16 bit standard word made up of 2 bytes therefor (16x16x16x16 or 256x256=65536)-1(for zero)=65535


JazzieB(Posted 2006) [#34]
2 bytes = word
4 bytes = longword

At least it was back in the day when I was programming in 68000. Terminology may have changed over the years, so fair enough if that's the case.

Just a quick note, Blitz doesn't refer to multiple byte values as words or longwords, instead they are...

2 bytes = short
4 bytes = int(eger)


D4NM4N(Posted 2006) [#35]
correct, word, longword, quadword, octaword....

but I think most people nowadays just say
8/12/16/24/32/64 etc. 'bit word'.

an integer in blitz is (i think!) a signed 32bit word . (or 4 bytes as u say with the first bit(or is it last?) specifying +/-)

LOL, its been way to long since archetecture 101 :)


Adam Novagen(Posted 2006) [#36]
but I think most people nowadays just say
8/12/16/24/32/64 etc. 'bit word'.

Twelve isn't usually part of that sequence... Is it?


Amanda Dearheart(Posted 2006) [#37]
xlsior,


There are 10 [2] types of people in this world. Those who understand binary, and those who don't
........
There are 11 [3] types of people in this world. Those who understand binary, and those who don't




One joke seems to repeat the other joke!


LineOf7s(Posted 2006) [#38]
One joke seems to repeat the other joke!


Yes, but the first joke is from the perspective of someone who clearly understands binary - and thus reads '10' as two instead of ten.

The second is from the perspective of someone who does not understand binary (to whatever degree), since the statement makes no sense using the binary number they did.

Two sides of the same coin. Not counting the edge, of course. :o)


D4NM4N(Posted 2006) [#39]
"twelve isn't usually part of that sequence... Is it?"

Not on conventional computer hardware, no. Some other machines like cameras, DACs, sound devices etc use so called '12 bit' words for whatever reason


RiverRatt(Posted 2006) [#40]
rgb=ReadPixelFast(x,y) And $FFFFFF
I'm sorry but I am still not sure what's going on in this
statement. How you can asign rgb a value of ReadPixelFast(x,y) And 16777215, or is that $FFFFFF, read as 255,255,255. In JFK's function here there seams to me no reason for And $FFFFFF, acept that it won't work without it.

Function SetMaskChannel(tex)
;this function will set the alpha channel of black pixels to be fully transparent
;(as required by masked textures using flag 4).

Local w,h,rgb,r,g,b,x,y,x2,y2,count,average_rgb
w=TextureWidth(tex)
h=TextureHeight(tex)
Dim tex_memory(w,h)
SetBuffer TextureBuffer(tex)
LockBuffer()
For y=0 To h-1
For x=0 To w-1
rgb=ReadPixelFast(x,y) And $FFFFFF
If rgb=0 Then
WritePixelFast x,y,0
Else
EndIf
Next
Next
UnlockBuffer()
SetBuffer BackBuffer()
End Function


jfk EO-11110(Posted 2006) [#41]
Readpixel will return a 32 bit value. When you mask it, using "AND $FFFFFF"or "AND $00FFFFFF" you will set the most upper 8 Bits to zero. This is the alpha channel. What's left is the 24 bit RGB value of the pixel or texel.

You have to see the 32 bits as this:

$AARRGGBB
(alpha red green blue)
where each channel has 8 bits or one byte, a value from 0 to 255 aka from $00 to $FF.

In this function I didn't care about the loaded alpha channel data, but used to create a new one based on RGB.


Subirenihil(Posted 2006) [#42]
rgb=ReadPixelFast(x,y) And $FFFFFF
I'm sorry but I am still not sure what's going on in this
statement. How you can asign rgb a value of ReadPixelFast(x,y) And 16777215, or is that $FFFFFF, read as 255,255,255. In JFK's function here there seams to me no reason for And $FFFFFF, except that it won't work without it.

$FFFFFF is the hex equivilant for 255,255,255 as you would use in a Color statement.
255 is the same as $FF
Colors are stored using 1 byte for red, 1 byte for green, and 1 byte for blue. But ReadPixel returns 4 bytes. The first byte is the alpha (not used in images but it is used in textures), the second is red, the third is green, and the fourth blue.

Because JFK didn't want the alpha channel, he threw it away:
"And $FFFFFF"
"And" performs a bitwise AND operation on the two numbers (the number returned by ReadPixel and $FFFFFF)
Boolean math - true or false - math is used on each corresponding bit. The three Boolean operations are:
And - if both bits are true then the result is true, otherwise the result is false
Or - if any of the bits is true then the result is true, otherwise the result is false
Xor - if the bits are different then the result is true, otherwise the result is false

So, for JFK's program, "xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx" is the binary form of the number returned by ReadPixel and "0000 0000 1111 1111 1111 1111 1111 1111" is the binary form of $FFFFFF (it's stored as $00FFFFFF but the zeros at the beginning are dropped for the sake of being concise). That said, here is what happens:
      Alpha        Red        Green       Blue
    xxxx xxxx   xxxx xxxx   xxxx xxxx   xxxx xxxx
And 0000 0000   1111 1111   1111 1111   1111 1111
=================================================
    0000 0000   xxxx xxxx   xxxx xxxx   xxxx xxxx

The alpha channel has been removed but left the RGB channels intact.

P.S. I noticed that people like my signature:) but that a number of you don't understand it. :(
"10" is binary for the decimal number "2", therefore when read by someone who understands binary, they read it correctly:
There are two kinds of people in the world - those that understand binary, and those that don't!

But because people learn decimal in school, the first time it is read, people think it says:
There are ten kinds of people in the world - those that understand binary, and those that don't!


P.P.S Did you know that you can count to 1023 (that's in decimal) on your fingers? (binary "0011 1111 1111", notice, ten ones - one for each finger. Just be careful who sees you show the number four or one-twenty-eight!)


RiverRatt(Posted 2006) [#43]
Thanks. I Think I get it now. That meens there are 3 kinds of people in the world Those that know binary, those who don't and those who will.


LineOf7s(Posted 2006) [#44]
Now I'm just being argumentative because my kids have annoyed me, but the people 'who will' will be in one of the other groups (presumably the "don't", but not necessarily) before they do. :o)


RiverRatt(Posted 2006) [#45]
If you flip a coin you can see my point. Heads on, tails off, while still in the air flipping, void, null, not.
Ney?


LineOf7s(Posted 2006) [#46]
Flipping coins, sure. But in that instance it can be in one of three states - being heads or tails when at rest doesn't preclude it from being neither (or both) whilst in motion.

But people (in the context of knowledge as we're discussing) are less like one-state-or-the-other as much as they're zero or non-zero. And if you accept they're either zero or non-zero, that doesn't leave a third alternative.

Of course, this all depends on one's definition of 'know'. For the sake of this argument, I'm using "to have no knowledge of, compared to having some knowledge of".


Sir Gak(Posted 2006) [#47]
D-Grafix:
Base 10(decimal) is 0123456789
Base 16(hexadecimal) is 0123456789ABCDF

In hex, one character= the less herd of NYBBLE.

Ther are 4 bits in a nibble and 2 nibbles in a BYTE(or 8 bits)

a collection of bytes is called a WORD

FF is an 8 bit word (2 nibbles) which is (16x16=256)-1(for zero)=255 (256 possible numbers inc. 0)

FFFF is a 16 bit word made up of 2 bytes (or 4 nibbles sometimes called long)

therefor (16x16x16x16 or 256x256=65536)-1(for zero)=65535



Ummm, two nybbles is a byte, not a word. A word is two bytes, not one byte.


Subirenihil(Posted 2006) [#48]
FF is an 8 bit word (2 nibbles) which is (16x16=256)-1(for zero)=255 (256 possible numbers inc. 0)

FFFF is a 16 bit word made up of 2 bytes (or 4 nibbles sometimes called long)

therefore (16x16x16x16 or 256x256=65536)-1(for zero)=65535


While it is true that 16x16=256 ($Fx$F=$100), HEX numbers, like binary and decimal, add multiples of the base for each digit.
Two examples:
123 is (1x<base squared>)+(2x<base>)+(3x1)
FB2A is (Fx<base cubed>)+(Bx<base squared>)+(2x<base>)+(Ax1)

Therefore $FFFF is:
$Fx($10x$10x$10)+$Fx($10x$10)+$Fx$10+$Fx$1
which in decimal is:
15x(16x16x16)+15x(16x16)+15x16+15x1

(If you haven't figured it out yet, the dollar sign in front of a number - or the letters A through F - means that it is a hexadecimal number in Blitz)


Subirenihil(Posted 2006) [#49]
In World of Warcraft, the punchcards in Gnomeragon have binary on them.
the binary says exactly what the text above says - something like "SUPER SECURE TRIPLE-ENCODED PUNCHCARD" - I don't remember for sure quite what they say.


JazzieB(Posted 2006) [#50]

While it is true that 16x16=256 ($Fx$F=$100), HEX numbers, like binary and decimal, add multiples of the base for each digit.



16 x 16 = 256 - yes, but.
$F x $F is $E1 (15 x 15 = 225). Tut-tut.

16 = $10, so $10 x $10 = $100 (16 x 16 = 256).

And just for fun, 10 x 10 is ALWAYS 100, no matter what base you're talking about.

Ahem. Sorry.


Adam Novagen(Posted 2006) [#51]
Ah, the wonderful & numerous powers of ten. :)


D4NM4N(Posted 2007) [#52]
"Ummm, two nybbles is a byte, not a word. A word is two bytes, not one byte."



i said '8 bit word' not 'WORD' theres a difference:

a 2 nyble structure is a BYTE or 8bitword (TECHNICALLY a word can be any length of bits but normally in the PC world, a word refers to collection of bytes not bits.) Orherwise how is it possible to have a so called '12 bit word'? (im not talking about intel based)

FOr example (randfomly found with google): http://www.keyless.com/PDF/8BitWord.pdf

A normal 'bog standard' WORD is 16 bits unless otherwise specified.

I did make another mistake tho, what i meant to say 32bit word is sometimes called long not 16 bit

LOL is this all helping riveratt or are you going mad yet (i think i am :)


jfk EO-11110(Posted 2007) [#53]
I have to agree, common knowledge is:
8 Bit= 1 Byte
16 Bit = 1 word
32 Bit = 1 Long
64 Bit = 1 very long - no wait a minute..well however

4 Bit = 1 Nibble tho this is rarely seen anymore.

There may be of course other lengths. I think what finally counts is how you gonna store it in RAM, as 8, 16 or 32 Bit value. This may be no issue in Blitz anyway.

I wold consider anything other than 4,8,16,32,64 simply as a value, eg. an "unsigned 15bit value".

BTW 1 Bit is the smallest unit they say. But actually there are some modem handshake modes that are using 1.5 stopbits. So what we have here is splitting a bit in 2 pieces! Probably we could use it to store 2 Bits in two halfbits. This could become a pretty cool utility - "magic ram multiplyer". :o)


D4NM4N(Posted 2007) [#54]
LOL, what do we call that then(1.5), 1 bit and a sniff :)


Sir Gak(Posted 2007) [#55]
LOL, what do we call that then(1.5), 1 bit and a sniff :)

How about a very simple "going-to-bite-you-but-haven't-bit-yet", or "gy" for short, using the first letters of the first-and-last words to form a word (not a WORD!) LOL!


GfK(Posted 2007) [#56]
This thread has gone stupid.


jfk EO-11110(Posted 2007) [#57]
No my fault. I just mentioned the "1.5 Stopbits" paradoxon:
http://www.eecs.umich.edu/dco/faq/matlab-6.5/help/toolbox/instrument/stopbits.html


Adam Novagen(Posted 2007) [#58]
Ah, well, we're game programmers; what can you expect, Gfk? If I didn't crack up at least once a week, I'd probably crack up! ^_^