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  
Forums Sitemap 
Dedicated Servers  
Download TestComplete 
JMSL Numerical Library 
IBM® developerWorks
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 / 2
    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! IBM Rational Systems Development e-Kit

    As systems increase in complexity, communication between systems and software teams becomes more and more difficult. Now, there’s a way to improve product quality and communication.<br />Read the “Model Driven Systems Development” white paper to see how. Also included in this kit are more educational white papers, customer examples, tutorials, informative Webcasts, and best practices for designing, building and managing systems.<br />
    FREE! Go There Now!


    IBM DB2 Deep Compression ROI Tool

    The IBM DB2 Deep Compression ROI tool is designed for DBA’s and IT management personnel to perform a clinical analysis of the cost savings gained from the Storage Optimization feature of DB2 9 for Linux, UNIX and Windows. The feature, also known as Deep Compression, compresses data that lies within a database by up to 80% at times.
    FREE! Go There Now!


    NEW! Whitepaper: Achieving consistency between business process models and operational guides

    Explore how Rational and WebSphere software enable enterprise documentation in SOA environments. Specifically, a new integration between IBM WebSphere® Business Modeler and IBM Rational® Method Composer software can help technical writers more easily keep enterprise operations manuals in sync with changes that are made to business processes, resulting in more accurate and timely documentation that benefits the entire enterprise.
    FREE! Go There Now!


    NEW! Addressing software-as-a-service challenges using Tivoli security and WebSphere solutions

    Building a software-as-a-service solution requires addressing a few key technical challenges. In this webcast, we'll focus on the role of IBM Tivoli Directory Server and WebSphere Portlet Factory in creating a Software as a Service solution. We will demonstrate how to use Tivoli Directory Server to prevent the user population of one tenant from accessing the virtual portal and portlet components of another tenant. We will also use the dynamic profile capability of WebSphere Portlet Factory to create multiple highly customized applications from one code base.
    FREE! Go There Now!


    NEW! Trial download: IBM Rational Method Composer V7.2

    Get a free trial download of the latest version of IBM Rational Method Composer V7.2 which helps you deliver customized yet consistent process guidance to your project teams and IT organization, and includes the latest version of IBM Rational Unified Process (RUP), which has provided process guidance to teams since 1996.
    FREE! Go There Now!


    NEW! Best Practices: The Integrated Project and Portfolio Management Platform.

    Hear how IBM Rational Project and Portfolio Management integrated solutions help teams put the right tools and processes in place to maximize the effectiveness and efficiency of project teams and ensure that the business vision is being executed correctly. Learn how to automate and integrate requirements prioritization, top-down project planning, communications and controls, and methodology deployment to keep your scope, costs, and schedules under control. Tackle with an end-to-end approach the management of scope and scope changes, usage of methodology to control and empower project teams, and optimization of resources to align activity costs with the overall project plan.
    FREE! Go There Now!


    Role of Integrated Requirements Management in Software Delivery

    As organizations integrate software into every aspect of business, they are constantly pressured to deliver faster, better, and cheaper results. Unfortunately, a “dis-integrated” software delivery approach reduces returns while increasing costs. This IBM Rational White Paper shows how Integrated Requirements Management aligns organizations around maximizing value and keeping pace with change.
    FREE! Go There Now!


    NEW! Build Web services with transport-level security using Rational Application Developer V7, Part 1: Build Web services and Web services clients

    Build secure Web services with transport-level security using IBM Rational Application Developer V7 and IBM WebSphere Application Server V6.1. Follow this three-part series for step-by-step instructions about how to develop Web services and clients, configure HTTP basic authentication, and configure HTTP over SSL (HTTPS). This first part of the series walks you through building a Web service for a simple calculator application. You generate and test two different types of Web services clients: a Java Platform, Enterprise Edition (Java EE) client and a stand-alone Java client. You also handle user-defined exceptions in Web services.
    FREE! Go There Now!


    NEW! Successful Change and Release Management for .NET

    Join this webcast to discover the key requirements for successful change and release management. Learn how to extend your .NET environment to improve productivity and collaboration, and address core problems afflicting team development. In this webcast, we’ll review typical challenges faced by customers and how to resolve them with the IBM Rational Change and Release Management solution, including Rational ClearCase, Rational ClearQuest and Rational Build Forge. Replay is available for 9 months.
    FREE! Go There Now!


    NEW! Evaluate Rational Business Developer V7.1

    Visit IBM developerWorks to download a free trial version of IBM Rational Business Developer V7.1. Rational Business Developer offers rapid and simplified development of business applications and services through Enterprise Generation Language (EGL) tools, generating Java or mainframe solutions while shielding developers from technical complexities.
    FREE! Go There Now!



    All FREE IBM® developerWorks Tools!

    MISCELLANEOUS CODE ARTICLES

    - 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
    - [PHP5] NOTIMEOUT PACKAGE
    - Class to return variables to a Flash movie.
    - BCGCD Greatest Common Denominator (Large Num...
    - HMAC
    - Binary to Decimal
    - Decimal to Binary using logs
    - web.framework v1.0.0
    - Shopping Cart Class






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway