The new forums will be named Coin Return (based on the most recent vote)! You can check on the status and timeline of the transition to the new forums here.
Please vote in the Forum Structure Poll. Polling will close at 2PM EST on January 21, 2025.
I really do work with a bunch of good people. this week was very hard (at least in terms of stress and difficult abstract problems to solve. I still would take this x 100 over jobs I had workin' retail or cutting weeds on a navy base)
but a little while just chattin' it up with some of the other people here (and some of our new interns) along with good booze and things are right with the world again
0
Donkey KongPutting Nintendo out of business with AI nipsRegistered Userregular
i'm going through the Python Classes on CodeAcademy and i just went over Bitwise operators...
What's a good example of a program where you need to use binary?
suppose you have a bunch of values which can be On or Off. You can pack a bunch of those into a small amount of memory with binary. Say there are 8 different flags that can be true or false. 11001100 would mean true, true, false, false, true, true, false, false. This process is called bitmasking.
You use binary OR to create the value. You use binary AND to check the value. EG: to check if the 3rd smallest bit is true then use _bitmask & 4
+2
21stCenturyCall me Pixel, or Pix for short![They/Them]Registered Userregular
i'm going through the Python Classes on CodeAcademy and i just went over Bitwise operators...
What's a good example of a program where you need to use binary?
suppose you have a bunch of values which can be On or Off. You can pack a bunch of those into a small amount of memory with binary. Say there are 8 different flags that can be true or false. 11001100 would mean true, true, false, false, true, true, false, false. This process is called bitmasking.
You use binary OR to create the value. You use binary AND to check the value. EG: to check if the 3rd smallest bit is true then use _bitmask & 4
I see, so that's why there was a lesson on bitmasking.
back in the days in the woods of Kitsap I found that at the start of every summer the way to toughen the feet up again was walking barefoot over hot pavement a lot
that'll get yer feet ready to deal with barnacles and sharp bits of clamshell and blackberry bushes
+1
Podlyyou unzipped me! it's all coming back! i don't like it!Registered Userregular
i'm going through the Python Classes on CodeAcademy and i just went over Bitwise operators...
What's a good example of a program where you need to use binary?
Well, there are three places where you'll realistically use binary directly:
When talking directly to hardware or using low level APIs that pack a bunch of data information into one word
(eg: 32 bits representing a color where the top 8 bits are red, next 8 green, next 8 blue, last 8 alpha or unused)
When implementing certain cryptographic or exotic mathematical operations
When using "flags". In their simplest form, flags let you cram as many booleans as you have bits in a given data type. So let's say you have a function call and it has a really diverse range of options but you don't want to break them all out into separate parameters because it would be ugly.
i'm going through the Python Classes on CodeAcademy and i just went over Bitwise operators...
What's a good example of a program where you need to use binary?
suppose you have a bunch of values which can be On or Off. You can pack a bunch of those into a small amount of memory with binary. Say there are 8 different flags that can be true or false. 11001100 would mean true, true, false, false, true, true, false, false. This process is called bitmasking.
You use binary OR to create the value. You use binary AND to check the value. EG: to check if the 3rd smallest bit is true then use _bitmask & 4
You'll see this frequently if you have to talk to OS-functions, since OS's are the kinds of things where you want to fit a much as you can into as small a block of memory as you can (generally).
For instance, in Windows if you need to make a call to manually create a window in the Win32 API, you will need to tell Windows things about how the window is drawn, or what type of window it is. So there might be a "window style" parameter that you need to fill in where you need to tell the function "this is a real window (not a balloon-tooltip, or some such) and it's also a toolbar-window (thin title-bar, special use)". So you would do something like:
int myWindowStyle = REAL_WINDOW | TOOLBAR_WINDOW;
Now, those "flags" (REAL_WINDOW, TOOLBAR_WINDOW) would be defined in an enum somewhere in a fashion like this: (ignore that I'm writing this in C# style and it would be C/C++ actually)
Note those integer-values (1, 2, 4) and think about how binary looks...
In our example above where we assigned that "myWindowStyle" variable, it is now assigned a value of 3 because of our bitwise-or:
00000001
XOR 00000010
=============
00000011
See how this is shaping up to work? Those flags/enum-values have specific values that allow us to get them in the right positions in a binary representation of the number. So basically, we end up with 8 positions per byte (so for a x86 integer, we'd get 32 positions) where we can store the values of flags. Each of those digits represents a different flag about what your window (or whatever your situation may be) is supposed to look and act like.
[ed] Beat'd like a rented mule. :oops: Also, I should stop trying to come up with code examples while drinking. :P
Posts
just not enough
not enough at alllllllllllllll
Have u considered going for a bullshit degree?
It's super chill
On the black screen
Yeah but there's not nearly enough "ruining weddings" games
On the black screen
just grueling work
I've known quite a few marriages ruined by WoW.
the "no true scotch man" fallacy.
They still make Zima?
-Indiana Solo, runner of blades
go lay in bed and call it a night
https://www.youtube.com/watch?v=szcXDIVEZTk
I'm still holding out hope a friend texts me. I want out of here.
scotch makes even a week in Build Hell better
i'm going through the Python Classes on CodeAcademy and i just went over Bitwise operators...
What's a good example of a program where you need to use binary?
Check out my site, the Bismuth Heart | My Twitter
I wish I could agree with this more than once
but a little while just chattin' it up with some of the other people here (and some of our new interns) along with good booze and things are right with the world again
I agreed with this so much I got my masters and left grad school.
Watching Grand Budapest hotel
Walked barefoot for a while, in an effort to toughen up feet
I have all of the blisters now
Was still very enjoyable!
suppose you have a bunch of values which can be On or Off. You can pack a bunch of those into a small amount of memory with binary. Say there are 8 different flags that can be true or false. 11001100 would mean true, true, false, false, true, true, false, false. This process is called bitmasking.
You use binary OR to create the value. You use binary AND to check the value. EG: to check if the 3rd smallest bit is true then use _bitmask & 4
I see, so that's why there was a lesson on bitmasking.
Gotcha, thanks, Riemann.
Check out my site, the Bismuth Heart | My Twitter
I'd recommend staying in-yard for feet toughening lessons.
so assign a power of 2 to each possible movement direction
1 = North
2 = East
4 = South
8 = West
16 = Up
32 = Down
etc...
then for every location in the text adventure game you have a single number which indicates valid exits.
So for a room where you can go North and South, _allowedExits = 1 | 4
and when the player tries to go west you test if(_allowedExists & 8)
etc...
It was all very Zen. The nature walk, the sounds, the focusing on not focusing on the pain ... :P
that'll get yer feet ready to deal with barnacles and sharp bits of clamshell and blackberry bushes
it seems like such a horrible time. and a significant chunk of your life.
i pretty much cleared the map
-Indiana Solo, runner of blades
Nerd RPG: The Nerdening
(One Click Hero)
Check out my site, the Bismuth Heart | My Twitter
Well, there are three places where you'll realistically use binary directly:
When talking directly to hardware or using low level APIs that pack a bunch of data information into one word
(eg: 32 bits representing a color where the top 8 bits are red, next 8 green, next 8 blue, last 8 alpha or unused)
When implementing certain cryptographic or exotic mathematical operations
When using "flags". In their simplest form, flags let you cram as many booleans as you have bits in a given data type. So let's say you have a function call and it has a really diverse range of options but you don't want to break them all out into separate parameters because it would be ugly.
Your flags might be: ...
So when you call drawCircle, you can just chain these flags together using bitwise OR to indicate all the ones you want:
Then inside the draw circle function, you can just do a flag check using the logical AND
around?
nothin' gonna ever keep him down
Happy Friday, [chat]
When words can hurt: MLS Edition.
You'll see this frequently if you have to talk to OS-functions, since OS's are the kinds of things where you want to fit a much as you can into as small a block of memory as you can (generally).
For instance, in Windows if you need to make a call to manually create a window in the Win32 API, you will need to tell Windows things about how the window is drawn, or what type of window it is. So there might be a "window style" parameter that you need to fill in where you need to tell the function "this is a real window (not a balloon-tooltip, or some such) and it's also a toolbar-window (thin title-bar, special use)". So you would do something like:
Now, those "flags" (REAL_WINDOW, TOOLBAR_WINDOW) would be defined in an enum somewhere in a fashion like this: (ignore that I'm writing this in C# style and it would be C/C++ actually)
Note those integer-values (1, 2, 4) and think about how binary looks...
In our example above where we assigned that "myWindowStyle" variable, it is now assigned a value of 3 because of our bitwise-or:
See how this is shaping up to work? Those flags/enum-values have specific values that allow us to get them in the right positions in a binary representation of the number. So basically, we end up with 8 positions per byte (so for a x86 integer, we'd get 32 positions) where we can store the values of flags. Each of those digits represents a different flag about what your window (or whatever your situation may be) is supposed to look and act like.
[ed] Beat'd like a rented mule. :oops: Also, I should stop trying to come up with code examples while drinking. :P