Jump to content

Merging two bit strings


Nolongerused3921

Recommended Posts

Well I've been working on my new site, and I am having a bit of trouble... Permissions are stored as 16-bit bit strings (010101.. etc), and while this is all fine and dandy... I want to add a group system, and by doing so - I need to figure out how to merge two bit strings (In case someone is in two groups).
So basically, I need to find out how to merge numbers like 0010100010 and 1001010011 so that I get 1011110011.

Anyone able to help me? I know I can write a function pretty easy to do this... But it would be pretty slow, so I need to find the best possible way to do this (PHP functions would be ideal)
Link to comment
https://forums.phpfreaks.com/topic/31757-merging-two-bit-strings/
Share on other sites

This can be done quite simply with the bitwise operators, like so:
[code]<?php
$a = bindec("0010100010");
$b = bindec("1001010011");
$c = $a | $b;

echo decbin($c);
?>[/code]

For more information, check the PHP manual, or even better, check out  [url=http://www.phpfreaks.com/forums/index.php/topic,113143.0.html]Barands examples in our FAQ[/url]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.