How to convert Binary_String into true Binary

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
myleow
Forum Contributor
Posts: 194
Joined: Mon Jun 21, 2004 7:05 pm
Location: California

How to convert Binary_String into true Binary

Post by myleow »

Is there a way to convert a Binary String meaning "101101011" into a Binary 101101011?

If it is by using Bitwise Manipulation, please point out the tutorial for bitwise operator in the PHP manual since i cannot find it.

What is got is a binary_string that is say "11111111", what i really want to do is add "00010000" from that binary_string and return the new binary_string.

Anyone know how to do this?

Thank you in advance

Regards
Mian
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

that's not a minus.. that'd be a xor, or complement - and...

[php_man]base_convert[/php_man]
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

There is also the [php_man]bindec[/php_man]() and [php_man]decbin[/php_man]() functions worth looking at...

Code: Select all

$bin_str = '11111111';
    $add = '00010000';
    echo decbin(bindec($bin_str) + bindec($add)); // 100001111
Post Reply