Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by scoobz1234 · Mar 05, 2018 at 07:53 PM · booleanbitwise

BitShifting and boolean functions

i currently have around 30 bools in a script on unity. I was told that maybe bit-shifting would be an easier way to do all this. but i am clueless when it comes to bit-shifting or bit anything. could anyone point me in the direction or maybe provide a small example of setting bits and ect.?

im setting bools, when buttons are pressed. which is read by another script that detects when specific bools are true together.. for example, when button 1 is paired with button 4 do this.. and so on and so forth.

if you need any more information please let me know and ill provide as much as i can... thank you for your help!

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image scoobz1234 · Mar 05, 2018 at 11:32 PM 0
Share

Your suggestion has helped allot, did some more digging and found out how to utilize bit shifting to eli$$anonymous$$ate 37 Booleans woo!

avatar image meat5000 ♦ scoobz1234 · Mar 06, 2018 at 11:00 AM 0
Share

Good job, maybe post some links or a bit of code for completeness

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by meat5000 · Mar 05, 2018 at 08:21 PM

Well an 'Int' has 32 bits. This is getting back to principles somewhat in that the idea is to treat each of those bits as a separate switch akin to something we'd do in electronic circuits. Bitwise commands are fast and straightforward (Bitwise is modifying the bits that make up the integer 'word'). This is similar to the way layers are handled. The idea of a bool... true or false, on or off is the same but its like separating out the bits of the integer and having a separate memory range for them. In this sense bitwise ops can help condense this kind of operation.

A bool has 1 'on/off'; its 1-bit so to speak. An int can contain 32 of them. If you want to get your teeth in to this in a way you can visualise it, look at Layermasks and in particular find the awesome How to use a Layermask answer here on UA.

Hope this helped nudge you in the right direction.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

75 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

FindWithTag or how to find if there any instances left 1 Answer

How to fix unstable boolean values? [possible bug] 1 Answer

issue with yield.WaitForSeconds(); 1 Answer

GUI.toggle always false 1 Answer

This boolean is messing up. Help? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges