Miscellaneous Code
  Home arrow Miscellaneous Code arrow Binary Conversion
Codewalker Forums 
  Tutorials  
Database Articles  
Miscellaneous  
Navigation Usability  
PEAR Articles  
Programming Basics  
Server Administration  
XML Tutorials  
  Reviews  
Database Book Reviews  
Linux Book Reviews  
Miscellaneous Reviews  
PHP Book Reviews  
PHP Software Reviews  
Server Admin Reviews  
SQL Tool Reviews  
  Code Gallery  
Content Management Code  
Contest Code  
Counters Code  
Database Code  
Date Time Code  
Discussion Board Code  
Email Code  
File Manipulation Code  
GUI Code  
Link Farm Code  
Miscellaneous Code  
Search Code  
Site Navigation Code  
User Management Code  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Download TestComplete 
Forums Sitemap 
Weekly Newsletter 
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
MISCELLANEOUS CODE

Binary Conversion
By: Codewalkers
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 3
    2002-09-05

    Table of Contents:

    Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Just a stupid little script i made when i was bored that can convert a number to binary form and vice versa. There is a working example here:
    http://www.schooliez.com/binary.php

    By : D1NGO

    <?php
    if($_GET['t'] == "b1")
    {
    if($Submit1)
    {
    makeBinary($binary);
    }
    else
    {
    echo <<<FORM
    <font size="2" face="Verdana, Arial, Helvetica, sans-serif">Please only choose numbers smaller than 255</font>
    <form name="form1" method="post" action="$PHP_SELF?t=b1">
    <p><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Convert this number:</font>
    <input type="text" name="binary">
    </p>
    <p>
    <input type="submit" name="Submit1" value="Convert">
    </p>
    </form>
    FORM;
    }



    }
    elseif($_GET['t'] == "b2")
    {
    if($Submit2)
    {
    if($num1 == 1)
    {
    $number = 128;
    }
    if($num2 == 1)
    {
    $number += 64;
    }
    if($num3 == 1)
    {
    $number += 32;
    }
    if($num4 == 1)
    {
    $number += 16;
    }
    if($num5 == 1)
    {
    $number += 8;
    }
    if($num6 == 1)
    {
    $number += 4;
    }
    if($num7 == 1)
    {
    $number += 2;
    }
    if($num8 == 1)
    {
    $number += 1;
    }
    echo "<font face=\"Verdana\" size=\"2\">The converted number is: $number</font>";
    }
    else{
    echo <<<FORM
    <font face="Verdana" size="2">Place the number "1" or "0" in the boxes</font>
    <form name="form1" method="post" action="$PHP_SELF?t=b2">
    <table width="431" border="0" cellpadding="0" cellspacing="0">
    <!--DWLayoutTable-->
    <tr>
    <td height="25" colspan="2" valign="top"> <input name="num1" type="text" size="1" maxlength="1">
    <input name="num2" type="text" size="1" maxlength="1"> <input name="num3" type="text" size="1" maxlength="1">
    <input name="num4" type="text" size="1" maxlength="1"> <input name="num5" type="text" size="1" maxlength="1">
    <input name="num6" type="text" size="1" maxlength="1"> <input name="num7" type="text" size="1" maxlength="1">
    <input name="num8" type="text" size="1" maxlength="1"> </td>
    </tr>
    <tr>
    <td width="110" height="24" valign="top"><input type="submit" name="Submit2" value="Convert"></td>
    <td width="321">&nbsp;</td>
    </tr>
    <tr>
    <td height="25">&nbsp;</td>
    <td>&nbsp;</td>
    </tr>
    </table>
    </form>
    FORM;
    }

    }
    else
    {
    echo <<<FORM
    <table width="591" border="0" cellpadding="5" cellspacing="1" bgcolor="#000000">
    <!--DWLayoutTable-->
    <tr>
    <td height="32" colspan="3" valign="middle" bgcolor="#FFFFFF"><div align="center"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Binary
    Conversions</font></div></td>
    </tr>
    <tr>
    <td width="140" height="24" valign="top" bgcolor="#FFFFFF"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Decimal
    to Binary:</font></td>
    <td width="89" valign="top" bgcolor="#FFFFFF"><form name="form1" method="post" action="$PHP_SELF?t=b1"><input type="submit" name="Submit" value="Go"></form></td>
    <td width="328" rowspan="3" valign="top" bgcolor="#FFFFFF"><font color="#CC0000" size="1" face="Verdana, Arial, Helvetica, sans-serif">Project
    designed and created by Rowan Hemsley</font></td>
    </tr>
    <tr>
    <td height="24" valign="top" bgcolor="#FFFFFF"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Binary
    to Decimal:</font></td>
    <td valign="top" bgcolor="#FFFFFF"><form name="form1" method="post" action="$PHP_SELF?t=b2"><input type="submit" name="Submit" value="Go"></form></td>
    </tr>
    <tr>
    <td height="2"></td>
    <td></td>
    </tr>
    </table>
    FORM;
    }

    function makeBinary($x)
    {
    if(($x - 128) >= 0)
    {
    $binary = '1';
    $x = $x - 128;
    }
    else
    {
    $binary = '0';
    }

    if(($x - 64) >= 0)
    {
    $binary = "$binary 1";
    $x = $x - 64;
    }
    else
    {
    $binary = "$binary 0";
    }

    if(($x - 32) >= 0)
    {
    $binary = "$binary 1";
    $x = $x - 32;
    }
    else
    {
    $binary = "$binary 0";
    }

    if(($x - 16) >= 0)
    {
    $binary = "$binary 1";
    $x = $x - 16;
    }
    else
    {
    $binary = "$binary 0";
    }

    if(($x - 8) >= 0)
    {
    $binary = "$binary 1";
    $x = $x - 8;
    }
    else
    {
    $binary = "$binary 0";
    }

    if(($x - 4) >= 0)
    {
    $binary = "$binary 1";
    $x = $x - 4;
    }
    else
    {
    $binary = "$binary 0";
    }

    if(($x - 2) >= 0)
    {
    $binary = "$binary 1";
    $x = $x - 2;
    }
    else
    {
    $binary = "$binary 0";
    }

    if(($x - 1) >= 0)
    {
    $binary = "$binary 1";
    $x = $x;
    echo "<font size=\"2\" face=\"Verdana, Arial, Helvetica, sans-serif\">$binary</font>";
    }
    else
    {
    $binary = "$binary 0";
    echo "<font size=\"2\" face=\"Verdana, Arial, Helvetica, sans-serif\">$binary</font>";
    }
    }
    ?>
    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

    More Miscellaneous Code Articles
    More By Codewalkers

     

    IBM® developerWorks developerWorks - FREE Tools!


    NEW! Download the free Web Application Security eKit

    Discover how IBM Rational AppScan Standard Edition can help you detext vulnerabilities in your web applications in the Web Application Security eKit. IBM Rational AppScan is a leading suite of automated web application security solutions that scan and test for common Web application vulnerabilities. The new Web Application Security eKit provides you with valuable resources, including white papers, demos, and additional information on the benefits of testing your Web applications.
    FREE! Go There Now!


    NEW! IBM Enterprise Modernization Sandbox for System z

    IBM Enterprise Modernization solutions help organizations evolve core IT systems towards modern architectures and technologies—reducing the burden of maintenance and freeing up resources to develop new business requirements and capabilities. With the IBM Enterprise Modernization Sandbox for System z you can evaluate IBM Enterprise Modernization solutions focused on five key areas: Assets, Architectures, Skills, Processes and Infrastructures, and Investment. Each solution is based upon real customer experiences and offers a proven path to get you started with your modernization projects.
    FREE! Go There Now!


    NEW! Improve your build process with IBM Rational Build Forge, Part 2: Automate builds for a real-world Tomcat project

    Learn how Rational Build Forge can extend a simple compile and package build process by adding customization and deployment capability. Go from a manual method to automating: checking for code changes; getting the latest source; compiling and packaging; customizing; copying to and restarting a deployment server; and sending e-mail notification that a new version is available.
    FREE! Go There Now!


    NEW! Krugle, developerWorks, and code search

    Ken Krugler, co-founder of code search company Krugle, and Laura Merling, vice president of Marketing and Business Development for Krugle, join to talk about the ins and outs of code search and what it means as a new feature for developerWorks users.
    FREE! Go There Now!


    NEW! Rational Asset Manager eKit

    Learn how to do more with your reusable assets with the free Rational Asset Manager eKit. The eKit includes demos on how Rational Asset Manager tracks and audits your assets in order to utilize them for reuse. Plus you’ll find white papers and a Webcast that discuss the challenges of a Service Oriented Architecture and how Rational Asset Manager can provide quick and effective solutions.
    FREE! Go There Now!


    NEW! Rational Build Forge Express eKit

    Rational Build Forge Express Edition is an automation framework that packages the latest enterprise-grade technologies into a reliable, flexible and robust configuration designed and priced specifically for small to midsize businesses. The new Rational Build Forge Express eKit provides you with valuable resources – including a case study, podcast, demo, and articles – to help you increase staff productivity, compress development cycles and deliver better software, fast.
    FREE! Go There Now!


    NEW! Rational Talks to You: Grady Booch on Architecture

    Join this Rational Talks to You teleconference on November 29 at 1:00 pm ET to participate in an interactive discusssion with Grady Booch around architecture and reuse. Get your questions answered!
    FREE! Go There Now!


    NEW! Software Change and Configuration Management Solution Guidelines

    This whitepaper provides areas to consider when evaluating any software configuration management solution. It addresses how the IBM solutions (Rational ClearCase and Rational ClearQuest) meet the needs and requirements of both project leaders and developers to provide successful Software Change and Configuration Management.
    FREE! Go There Now!


    NEW! Webcast: IBM Rational Build Forge - Beyond the Build

    The discipline of assembling and delivering software is maturing beyond standard developer-centric compile/test software builds. The end-to-end software development lifecycle is emerging as the new focus moves “Beyond the Build.” Join this on demand webcast to learn about methods for streamlining software delivery and key capabilities of the IBM Rational Build Forge framework for automating build and release management in environments of any size.
    FREE! Go There Now!


    NEW! Webcast: Introducing the new Information Server and Solutions community: LeverageInformation

    User communities play an important role in communication and collaboration around products, solutions and other areas of special interest to members. Successful communities are able to provide the right mix of content and services to deliver a value proposition that resonates with each audience. Join Tom Inman, VP of Marketing for Information and Platform Solutions as he introduces the new LeverageINFORMATION community. During this webcast, learn about the value provided by the community and how customers and partners derive value from the community in addressing their own technical and business challenges.
    FREE! Go There Now!



    All FREE IBM® developerWorks Tools!

    MISCELLANEOUS CODE ARTICLES

    - A Web App Based on a Model for the CodeIgnit...
    - Completing a Model for the CodeIgniter PHP F...
    - Validating Input Data with the CodeIgniter P...
    - Deleting Database Records with the CodeIgnit...
    - Inserting Database Records with a CodeIgnite...
    - Fetching Database Rows with a Model for the ...
    - Model Data and Validation Rules for a Generi...
    - Building a Generic Model for the CodeIgniter...
    - upload image to database sql
    - Random Password Generator
    - BCroot, get the root of a number with BC fun...
    - Find pi in a high precision
    - [PHP5] FORMCHECKER : data validation
    - SPL and ITERATOR : examples
    - Xml with Rss Feeds





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek