Welcome to the most active Linux Forum on the web.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 04-03-2009, 04:09 PM   #1
LQ Newbie
Registered: Jan 2008
Posts: 20

Rep: Reputation: 0
Storing multiple options in a single variable (binary addition?)

Sorry but I have no idea what this is called and googleing "Binary Options" just brings back financial websites.

I want to store a set of options as an integer e.g.

Option 1 = 1
Option 2 = 2
Option 3 = 4
Option 4 = 8

So if I tick 1 & 3 the value is 5, or 2, 3 & 4 the value is 14.

I want to do this in PHP, is there a pre defined function for it or does anyone know a pseudo code example?

I can probably store the values without a problem as it's just addition, but I won't know how to then read them properly. I can't think of a simple way of doing it.

Also does anyone know what this is called so I could Google it a bit more.
Old 04-03-2009, 04:38 PM   #2
LQ Newbie
Registered: Jan 2008
Posts: 20

Original Poster
Rep: Reputation: 0

Someone at work just came back from the pub, Bitwise is what I need and I've found some info.

Sorry didn't expect anyone back in the office until Monday.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Storing table in variable DeepSeaNautilus Linux - Software 5 04-04-2009 02:45 PM
Storing part of a filename as a variable VTGuitarMan Programming 5 03-12-2008 07:47 AM
Storing binary data in MySQL take 2 drspin Programming 5 05-05-2006 04:26 PM
storing octal value in char variable hubabuba Programming 1 04-17-2006 01:53 AM
Can I have multiple desktop/manager options with single user? timsch75 Slackware 5 08-18-2004 06:10 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:29 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration