<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
  <channel>
    <title>'Binary to decimal and Decimal to binary conversion' Thread RSS Feed</title>
    <link>http://www.programmersheaven.com/</link>
    <description>Contains the latest posts from the thread 'Binary to decimal and Decimal to binary conversion' posted on the 'Pascal' forum at Programmer's Heaven.</description>
    <language>en</language>
    <copyright>Copyright 2013 Programmers Heaven</copyright>
    <pubDate>Sat, 18 May 2013 23:58:22 -0700</pubDate>
    <lastBuildDate>Sat, 18 May 2013 23:58:22 -0700</lastBuildDate>
    <generator>Argotic Syndication Framework 2007.3.0.1, http://www.codeplex.com/Argotic</generator>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <ttl>360</ttl>
    <image>
      <url>http://www.programmersheaven.com/images/ph.gif</url>
      <title>Programmers Heaven</title>
      <link>http://www.programmersheaven.com/</link>
      <width>88</width>
      <height>31</height>
    </image>
    <item>
      <title>Binary to decimal and Decimal to binary conversion</title>
      <link>http://www.programmersheaven.com/mb/pasprog/389747/389747/binary-to-decimal-and-decimal-to-binary-conversion/</link>
      <description>can anyone help me with this binary to decimal numbers then another one is decimal to binary tnx plus if you know something about binary to octal please help thanks&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/pasprog/389747/389747/binary-to-decimal-and-decimal-to-binary-conversion/</guid>
      <pubDate>Fri, 24 Apr 2009 05:16:56 -0700</pubDate>
      <category>Pascal</category>
    </item>
    <item>
      <title>Re: Binary to decimal and Decimal to binary conversion</title>
      <link>http://www.programmersheaven.com/mb/pasprog/389747/389764/re-binary-to-decimal-and-decimal-to-binary-conversion/#389764</link>
      <description>: can anyone help me with this binary to decimal numbers then another &lt;br /&gt;
: one is decimal to binary tnx plus if you know something about binary &lt;br /&gt;
: to octal please help thanks&lt;br /&gt;
: &lt;br /&gt;
&lt;br /&gt;
Decimal to binary ( and vice versa ) + binary to octal ( and vice versa ) demo (not the nicest code but works):&lt;pre class="sourcecode"&gt;&lt;span style="color: Blue;"&gt;program dec_bin_oct;

const po2:array[0..7] of byte=(1,2,4,8,16,32,64,128); {powers of 2}
      bin:array[false..true] of char='01';
      oct:array[0..7] of char='01234567';

{Decimal to binary}
function dec2bin(b:byte):string;
 var s:string;
     i:byte;
 begin
  s:='';
  for i:=7 downto 0 do
   s:=s+bin[(po2[i] and b=po2[i])];
  dec2bin:=s;
 end;

{Binary ot decimal}
function bin2dec(s:string):byte;
 var l:byte absolute s; {lenght of s}
     i,b:byte;
 begin
  b:=0;
  while l&amp;lt;8 do s:=bin[false]+s;
  if l&amp;gt;8 then s:=copy(s,l-7,8);
  for i:=1 to l do
  if s[i]=bin[true] then b:=b+po2[8-i];
  bin2dec:=b;
 end;

{Binary to octal}
function bin2oct(b:string):string;
 var s:string;
     l:byte absolute b; {lenght of b}
     i:byte;
 begin
  while ((l mod 3)&amp;lt;&amp;gt;0) do b:=bin[false]+b;
  s:='';
  for i:=1 to (l div 3) do
   s:=s+oct[bin2dec(b[pred(i)*3+1]+b[pred(i)*3+2]+b[p
red(i)*3+3])];
  bin2oct:=s;
 end;

{Octal to binary}
function oct2bin(b:string):string;
 var l:byte absolute b;
     i:byte;
     s:string;
 begin
  s:='';
  for i:=1 to l do
   s:=s+copy(dec2bin(ord(b[i])-48),6,3);
  oct2bin:=s;
 end;


var n:byte;

begin
 write(#13#10,'Enter a decimal :');readln(n);
 writeln(n,' in binary :',dec2bin(n),', in decimal :',bin2dec(dec2bin(n)));
 writeln(n,' in octal :',bin2oct(dec2bin(n)),' in binary: ',oct2bin(bin2oct(dec2bin(n))));
 readln;
end.
&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/pasprog/389747/389764/re-binary-to-decimal-and-decimal-to-binary-conversion/#389764</guid>
      <pubDate>Fri, 24 Apr 2009 11:33:22 -0700</pubDate>
      <category>Pascal</category>
    </item>
    <item>
      <title>Re: Binary to decimal and Decimal to binary conversion</title>
      <link>http://www.programmersheaven.com/mb/pasprog/389747/390183/re-binary-to-decimal-and-decimal-to-binary-conversion/#390183</link>
      <description>haha tnx but can you explain me every line hahaha im little confuse about the program but it works i just cant explain how ...&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/pasprog/389747/390183/re-binary-to-decimal-and-decimal-to-binary-conversion/#390183</guid>
      <pubDate>Thu, 30 Apr 2009 20:59:15 -0700</pubDate>
      <category>Pascal</category>
    </item>
    <item>
      <title>Re: Binary to decimal and Decimal to binary conversion</title>
      <link>http://www.programmersheaven.com/mb/pasprog/389747/390290/re-binary-to-decimal-and-decimal-to-binary-conversion/#390290</link>
      <description>can you help me on this?how does this work?&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/pasprog/389747/390290/re-binary-to-decimal-and-decimal-to-binary-conversion/#390290</guid>
      <pubDate>Sun, 03 May 2009 05:34:42 -0700</pubDate>
      <category>Pascal</category>
    </item>
    <item>
      <title>Re: Binary to decimal and Decimal to binary conversion</title>
      <link>http://www.programmersheaven.com/mb/pasprog/389747/390314/re-binary-to-decimal-and-decimal-to-binary-conversion/#390314</link>
      <description>All data is stored in the computer in some sort of binary format.  I assume that what you need is a way to convert that binary representation into a string of 1s and 0s representing the same thing.  Converting integers to/from (machine) binary from/to a decimal string representation is accomplished in Pascal using the procedures &lt;strong&gt;Str&lt;/strong&gt; and &lt;strong&gt;Val&lt;/strong&gt;.  This unit defines &lt;strong&gt;BinStr&lt;/strong&gt; and &lt;strong&gt;BinVal&lt;/strong&gt; which do the same for binary.  &lt;strong&gt;OctStr&lt;/strong&gt; and &lt;strong&gt;OctVal&lt;/strong&gt; do the same for octal.&lt;br /&gt;
&lt;pre class="sourcecode"&gt;
Unit StrVal ;

interface

   Procedure BinStr (i : Integer ; Var s : String) ;
   Procedure BinVal (s : String ;  Var i : Integer ; Var Code : Integer) ;
   Procedure OctStr (i : Integer ; Var s : String) ;
   Procedure OctVal (s : String ;  Var i : Integer ; Var Code : Integer) ;


implementation

   Procedure BinStr(i : Integer ; Var s : String) ;
   {
      convert an integer to a string in binary format
   }
   begin
      if i &amp;lt; 0 then begin
         i := -i ;
         Str(i, s) ;
         s := '-' + s
      end
      else begin 
         s := '' ;
         while i &amp;gt; 0 do begin
            if i MOD 2 &amp;gt; 0 then
               s := '1' + s
            else
               s := '0' + s ;
            i := i DIV 2
         end ;
         if Length (s) = 0 then
            s := '0'
      end ;
   end ;

   Procedure BinVal (s : String ; Var i : Integer ; Var Code : Integer) ;
   {
      convert a string in binary format to an integer
   }
   Var
      Sign, j, n  : Integer ;

   begin
      if s[1] IN ['+', '-', '0', '1'] then begin { is 1st char valid? }
         case s[i] of
            '-' : begin
                     Sign := -1 ;
                     n    := 2
                  end ;
            '+' : begin
                     Sign := 1 ;
                     n    := 2
                  end ;
            else  begin
                     Sign := 1 ;
                     n    := 1
                  end
         end ; { case }
         i := 0 ;
         for j := n to Length(s) do
            if s[j] IN ['0', '1'] then
               i := 2*i + Ord(s[j]) - Ord('0')
            else begin
               Code := j ;
               Exit
            end ;
         i := Sign * i
      end
      else begin
         i     := 0 ;
         Code  := 1
      end
   end ;

   Procedure OctStr(i : Integer ; Var s : String) ;
   {
      convert an integer to a string in octal format
   }
   begin
      if i &amp;lt; 0 then begin
         i := -i ;
         Str(i, s) ;
         s := '-' + s
      end
      else begin 
         s := '' ;
         while i &amp;gt; 0 do begin
            s := Chr((i MOD 8) + Ord('0')) + s ;
            i := i DIV 8
         end ;
         if Length (s) = 0 then
            s := '0'
      end ;
   end ;

   Procedure OctVal (s : String ; Var i : Integer ; Var Code : Integer) ;
   {
      convert a string in octal format to an integer
   }
   Var
      Sign, j, n  : Integer ;

   begin
      if s[1] IN ['+', '-', '0' .. '7'] then begin { is 1st char valid? }
         case s[i] of
            '-' : begin
                     Sign := -1 ;
                     n    := 2
                  end ;
            '+' : begin
                     Sign := 1 ;
                     n    := 2
                  end ;
            else  begin
                     Sign := 1 ;
                     n    := 1
                  end
         end ; { case }
         i := 0 ;
         for j := n to Length(s) do
            if s[j] IN ['0' .. '7'] then
               i := 8*i + Ord(s[j]) - Ord('0')
            else begin
               Code := j ;
               Exit
            end ;
         i := Sign * i
      end
      else begin
         i     := 0 ;
         Code  := 1
      end
   end ;

end.
&lt;pre class="sourcecode"&gt;
&lt;/pre&gt;&lt;/pre&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/pasprog/389747/390314/re-binary-to-decimal-and-decimal-to-binary-conversion/#390314</guid>
      <pubDate>Sun, 03 May 2009 11:18:45 -0700</pubDate>
      <category>Pascal</category>
    </item>
    <item>
      <title>Re: Binary to decimal and Decimal to binary conversion</title>
      <link>http://www.programmersheaven.com/mb/pasprog/389747/390325/re-binary-to-decimal-and-decimal-to-binary-conversion/#390325</link>
      <description>Binary is stored as a string of bits (0's and 1's) and each represent a value (power of 2).&lt;pre class="sourcecode"&gt;Example:
Bit number: 7    6    5    4    3    2    1    0
Binary:&lt;strong&gt;     1    0    1    1    0    1    0    1&lt;/strong&gt;
Values:&lt;strong&gt;    128   64   32   16   8    4    2    1 &lt;/strong&gt;

Converting to decimal: 1*128 + 0*64 + 1*32 + 1*16 + 0*8 + 1*4 + 0*2 + 1*1 = 171
(because: 2^7=128, 2^6=64, 2^5=32....)

Converting a decimal to binary could be done with the aid of the
bitwise &lt;strong&gt;and&lt;/strong&gt; or the &lt;strong&gt;mod&lt;/strong&gt; (modulo) operator, the latter 
being more cpu intensive, therefore slower. Starting from the highest 
bit check for each bit, if set add &lt;strong&gt;1&lt;/strong&gt; to output else &lt;strong&gt;0&lt;/strong&gt;
(e.g. if (value and 64=64) then {&amp;lt;-- bit6 is set} )&lt;/pre&gt;Octal numbers are a bit different but the idea is the same...&lt;pre class="sourcecode"&gt;Binary to octal:
Bit number: 7    6    5    4    3    2    1    0
Binary:&lt;strong&gt;     1    0    1    1    0    1    0    1&lt;/strong&gt;
At his point left pad the bits with &lt;strong&gt;0&lt;/strong&gt;'s to have the length dividable by 3, adding 0's won't change it's value
So:  010110101  ( &amp;lt;-- added one 0 )
Next divide the binary string to pieces of 3, that's why we added 0's to make this possible
--&amp;gt;&lt;strong&gt;   010  110  101&lt;/strong&gt;
Now convert these triplets into their decimal value:
 010 = 0*4 + 1*2 + 0*1 = 2
 110 = 1*4 + 1*2 + 0*1 = 6
 101 = 1*4 + 0*2 + 1*1 = 5
By concatenating these values results in the octal number: &lt;strong&gt;265&lt;/strong&gt;
To convert octal to binary use the same algorithm backwards...
&lt;/pre&gt;&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/pasprog/389747/390325/re-binary-to-decimal-and-decimal-to-binary-conversion/#390325</guid>
      <pubDate>Sun, 03 May 2009 17:56:11 -0700</pubDate>
      <category>Pascal</category>
    </item>
    <item>
      <title>Re: Binary to decimal and Decimal to binary conversion</title>
      <link>http://www.programmersheaven.com/mb/pasprog/389747/429899/re-binary-to-decimal-and-decimal-to-binary-conversion/#429899</link>
      <description>:))&lt;br /&gt;
&lt;pre class="sourcecode"&gt;
{Binary to decimal
This function gets binary number as a String and will return decimaal number as an Integer}
function bin2dec(getal:String): Integer;
  var
    I: Integer;
    uitvoer : Integer;
    begin
    uitvoer := 0;
      for I := 0 to length(getal) -1 do
        begin
          if getal[length(getal) - I] = '1' then
           begin
             uitvoer := uitvoer + 1 shl (I);
           end;
      end;
      bin2dec:=uitvoer;
  end;

{Returns a string in which the character order of a specified string is reversed}
function ReverseString(S : String): String;
      var
      i : Integer;
        begin
        Result := '';
        For i := Length(S) DownTo 1 Do
          Begin
            Result := Result + Copy(S,i,1) ;
          End;
      End;

  {
 Decimaal to binary
 This function gets a decimal number as Integer and will return the binary number as a String
}
function dec2bin(getal:Integer): String;
  var
  uitvoer:String;
  getal_met_rest : Real;
  begin
  while getal &amp;gt; 0 do
    begin
        getal_met_rest := getal / 2;
        if frac(getal_met_rest) = 0
          then uitvoer := uitvoer + '0'
          else uitvoer := uitvoer + '1';
        getal := trunc(getal_met_rest);
    end;
  dec2bin:=ReverseString(uitvoer);
  end;

 {
 This function gets a decimal number as an Integer and will return the HEX number as a String
 }
function dec2hex(getal:Integer): String;
  var
  uitvoer: String;
  getal_met_rest : Real;
  S : Integer;
  begin
    while getal &amp;gt; 0 do
         begin
            getal_met_rest := getal / 16;
            S := getal - (trunc(getal_met_rest)*16);
            if S &amp;lt; 10 then uitvoer := uitvoer + IntToStr(S);
            if S = 10 then uitvoer := uitvoer + 'A';
            if S = 11 then uitvoer := uitvoer + 'B';
            if S = 12 then uitvoer := uitvoer + 'C';
            if S = 13 then uitvoer := uitvoer + 'D';
            if S = 14 then uitvoer := uitvoer + 'E';
            if S = 15 then uitvoer := uitvoer + 'F';
            getal := trunc(getal_met_rest);
         end;
    dec2hex:=ReverseString(uitvoer);
  end;

  {
 This function gets hex number as a String and will return the decimamaal number as an Integer
 }
 function hex2dec(getal: String) : Integer;
    var
    uitvoer: Integer;
    I: Integer;
    dec_number: Integer;
    begin
    uitvoer := 0;
    getal := ReverseString(getal);
      for I := 1 to length(getal) do
        begin
              if getal[I] = '1'  then dec_number := 1;
              if getal[I] = '2'  then dec_number := 2;
              if getal[I] = '3'  then dec_number := 3;
              if getal[I] = '4'  then dec_number := 4;
              if getal[I] = '5'  then dec_number := 5;
              if getal[I] = '6'  then dec_number := 6;
              if getal[I] = '7'  then dec_number := 7;
              if getal[I] = '8'  then dec_number := 8;
              if getal[I] = '9'  then dec_number := 9;
              if getal[I] = 'a'  then dec_number := 10;
              if getal[I] = 'A'  then dec_number := 10;
              if getal[I] = 'b'  then dec_number := 11;
              if getal[I] = 'B'  then dec_number := 11;
              if getal[I] = 'c'  then dec_number := 12;
              if getal[I] = 'C'  then dec_number := 12;
              if getal[I] = 'd'  then dec_number := 13;
              if getal[I] = 'D'  then dec_number := 13;
              if getal[I] = 'e'  then dec_number := 14;
              if getal[I] = 'E'  then dec_number := 14;
              if getal[I] = 'f'  then dec_number := 15;
              if getal[I] = 'F'  then dec_number := 15;

             uitvoer := uitvoer + (dec_number * trunc(Power(16, I-1)));
        end;
      hex2dec:=uitvoer;
    end;

 {
 This function gets a decimal number as an Integer and will return the octal number as a String
 }
function dec2oct(getal:Integer): String;
  var
  uitvoer: String;
  getal_met_rest : Real;
  begin
    while getal &amp;gt; 0 do
         begin
            getal_met_rest := getal / 8;
            uitvoer := uitvoer + IntToStr(getal - (trunc(getal_met_rest)*8));
            getal := trunc(getal_met_rest);
         end;
    dec2oct:=ReverseString(uitvoer);
  end;

 {
 This function gets octal number as a String and will return the decimamaal number as an Integer
 }
 function oct2dec(getal: String) : Integer;
    var
    uitvoer: Integer;
    I: Integer;
    begin
    uitvoer := 0;
    getal := ReverseString(getal);
      for I := 1 to length(getal) do
        begin
             uitvoer := uitvoer + (StrToInt(getal[I]) * trunc(Power(8, I-1)));
        end;
      oct2dec:=uitvoer;
    end;

&lt;/pre&gt;&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/pasprog/389747/429899/re-binary-to-decimal-and-decimal-to-binary-conversion/#429899</guid>
      <pubDate>Sun, 21 Oct 2012 09:26:10 -0700</pubDate>
      <category>Pascal</category>
    </item>
    <item>
      <title>Re: Binary to decimal and Decimal to binary conversion</title>
      <link>http://www.programmersheaven.com/mb/pasprog/389747/429900/re-binary-to-decimal-and-decimal-to-binary-conversion/#429900</link>
      <description>:))&lt;br /&gt;
&lt;pre class="sourcecode"&gt;
{Binary to decimal
This function gets binary number as a String and will return decimaal number as an Integer}
function bin2dec(getal:String): Integer;
  var
    I: Integer;
    uitvoer : Integer;
    begin
    uitvoer := 0;
      for I := 0 to length(getal) -1 do
        begin
          if getal[length(getal) - I] = '1' then
           begin
             uitvoer := uitvoer + 1 shl (I);
           end;
      end;
      bin2dec:=uitvoer;
  end;

{Returns a string in which the character order of a specified string is reversed}
function ReverseString(S : String): String;
      var
      i : Integer;
        begin
        Result := '';
        For i := Length(S) DownTo 1 Do
          Begin
            Result := Result + Copy(S,i,1) ;
          End;
      End;

  {
 Decimaal to binary
 This function gets a decimal number as Integer and will return the binary number as a String
}
function dec2bin(getal:Integer): String;
  var
  uitvoer:String;
  getal_met_rest : Real;
  begin
  while getal &amp;gt; 0 do
    begin
        getal_met_rest := getal / 2;
        if frac(getal_met_rest) = 0
          then uitvoer := uitvoer + '0'
          else uitvoer := uitvoer + '1';
        getal := trunc(getal_met_rest);
    end;
  dec2bin:=ReverseString(uitvoer);
  end;

 {
 This function gets a decimal number as an Integer and will return the HEX number as a String
 }
function dec2hex(getal:Integer): String;
  var
  uitvoer: String;
  getal_met_rest : Real;
  S : Integer;
  begin
    while getal &amp;gt; 0 do
         begin
            getal_met_rest := getal / 16;
            S := getal - (trunc(getal_met_rest)*16);
            if S &amp;lt; 10 then uitvoer := uitvoer + IntToStr(S);
            if S = 10 then uitvoer := uitvoer + 'A';
            if S = 11 then uitvoer := uitvoer + 'B';
            if S = 12 then uitvoer := uitvoer + 'C';
            if S = 13 then uitvoer := uitvoer + 'D';
            if S = 14 then uitvoer := uitvoer + 'E';
            if S = 15 then uitvoer := uitvoer + 'F';
            getal := trunc(getal_met_rest);
         end;
    dec2hex:=ReverseString(uitvoer);
  end;

  {
 This function gets hex number as a String and will return the decimamaal number as an Integer
 }
 function hex2dec(getal: String) : Integer;
    var
    uitvoer: Integer;
    I: Integer;
    dec_number: Integer;
    begin
    uitvoer := 0;
    getal := ReverseString(getal);
      for I := 1 to length(getal) do
        begin
              if getal[I] = '1'  then dec_number := 1;
              if getal[I] = '2'  then dec_number := 2;
              if getal[I] = '3'  then dec_number := 3;
              if getal[I] = '4'  then dec_number := 4;
              if getal[I] = '5'  then dec_number := 5;
              if getal[I] = '6'  then dec_number := 6;
              if getal[I] = '7'  then dec_number := 7;
              if getal[I] = '8'  then dec_number := 8;
              if getal[I] = '9'  then dec_number := 9;
              if getal[I] = 'a'  then dec_number := 10;
              if getal[I] = 'A'  then dec_number := 10;
              if getal[I] = 'b'  then dec_number := 11;
              if getal[I] = 'B'  then dec_number := 11;
              if getal[I] = 'c'  then dec_number := 12;
              if getal[I] = 'C'  then dec_number := 12;
              if getal[I] = 'd'  then dec_number := 13;
              if getal[I] = 'D'  then dec_number := 13;
              if getal[I] = 'e'  then dec_number := 14;
              if getal[I] = 'E'  then dec_number := 14;
              if getal[I] = 'f'  then dec_number := 15;
              if getal[I] = 'F'  then dec_number := 15;

             uitvoer := uitvoer + (dec_number * trunc(Power(16, I-1)));
        end;
      hex2dec:=uitvoer;
    end;

 {
 This function gets a decimal number as an Integer and will return the octal number as a String
 }
function dec2oct(getal:Integer): String;
  var
  uitvoer: String;
  getal_met_rest : Real;
  begin
    while getal &amp;gt; 0 do
         begin
            getal_met_rest := getal / 8;
            uitvoer := uitvoer + IntToStr(getal - (trunc(getal_met_rest)*8));
            getal := trunc(getal_met_rest);
         end;
    dec2oct:=ReverseString(uitvoer);
  end;

 {
 This function gets octal number as a String and will return the decimamaal number as an Integer
 }
 function oct2dec(getal: String) : Integer;
    var
    uitvoer: Integer;
    I: Integer;
    begin
    uitvoer := 0;
    getal := ReverseString(getal);
      for I := 1 to length(getal) do
        begin
             uitvoer := uitvoer + (StrToInt(getal[I]) * trunc(Power(8, I-1)));
        end;
      oct2dec:=uitvoer;
    end;

&lt;/pre&gt;&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/pasprog/389747/429900/re-binary-to-decimal-and-decimal-to-binary-conversion/#429900</guid>
      <pubDate>Sun, 21 Oct 2012 09:28:43 -0700</pubDate>
      <category>Pascal</category>
    </item>
    <item>
      <title>Re: Binary to decimal and Decimal to binary conversion</title>
      <link>http://www.programmersheaven.com/mb/pasprog/389747/429901/re-binary-to-decimal-and-decimal-to-binary-conversion/#429901</link>
      <description>:))&lt;br /&gt;
&lt;pre class="sourcecode"&gt;
{Binary to decimal
This function gets binary number as a String and will return decimaal number as an Integer}
function bin2dec(getal:String): Integer;
  var
    I: Integer;
    uitvoer : Integer;
    begin
    uitvoer := 0;
      for I := 0 to length(getal) -1 do
        begin
          if getal[length(getal) - I] = '1' then
           begin
             uitvoer := uitvoer + 1 shl (I);
           end;
      end;
      bin2dec:=uitvoer;
  end;

{Returns a string in which the character order of a specified string is reversed}
function ReverseString(S : String): String;
      var
      i : Integer;
        begin
        Result := '';
        For i := Length(S) DownTo 1 Do
          Begin
            Result := Result + Copy(S,i,1) ;
          End;
      End;

  {
 Decimaal to binary
 This function gets a decimal number as Integer and will return the binary number as a String
}
function dec2bin(getal:Integer): String;
  var
  uitvoer:String;
  getal_met_rest : Real;
  begin
  while getal &amp;gt; 0 do
    begin
        getal_met_rest := getal / 2;
        if frac(getal_met_rest) = 0
          then uitvoer := uitvoer + '0'
          else uitvoer := uitvoer + '1';
        getal := trunc(getal_met_rest);
    end;
  dec2bin:=ReverseString(uitvoer);
  end;

 {
 This function gets a decimal number as an Integer and will return the HEX number as a String
 }
function dec2hex(getal:Integer): String;
  var
  uitvoer: String;
  getal_met_rest : Real;
  S : Integer;
  begin
    while getal &amp;gt; 0 do
         begin
            getal_met_rest := getal / 16;
            S := getal - (trunc(getal_met_rest)*16);
            if S &amp;lt; 10 then uitvoer := uitvoer + IntToStr(S);
            if S = 10 then uitvoer := uitvoer + 'A';
            if S = 11 then uitvoer := uitvoer + 'B';
            if S = 12 then uitvoer := uitvoer + 'C';
            if S = 13 then uitvoer := uitvoer + 'D';
            if S = 14 then uitvoer := uitvoer + 'E';
            if S = 15 then uitvoer := uitvoer + 'F';
            getal := trunc(getal_met_rest);
         end;
    dec2hex:=ReverseString(uitvoer);
  end;

  {
 This function gets hex number as a String and will return the decimamaal number as an Integer
 }
 function hex2dec(getal: String) : Integer;
    var
    uitvoer: Integer;
    I: Integer;
    dec_number: Integer;
    begin
    uitvoer := 0;
    getal := ReverseString(getal);
      for I := 1 to length(getal) do
        begin
              if getal[I] = '1'  then dec_number := 1;
              if getal[I] = '2'  then dec_number := 2;
              if getal[I] = '3'  then dec_number := 3;
              if getal[I] = '4'  then dec_number := 4;
              if getal[I] = '5'  then dec_number := 5;
              if getal[I] = '6'  then dec_number := 6;
              if getal[I] = '7'  then dec_number := 7;
              if getal[I] = '8'  then dec_number := 8;
              if getal[I] = '9'  then dec_number := 9;
              if getal[I] = 'a'  then dec_number := 10;
              if getal[I] = 'A'  then dec_number := 10;
              if getal[I] = 'b'  then dec_number := 11;
              if getal[I] = 'B'  then dec_number := 11;
              if getal[I] = 'c'  then dec_number := 12;
              if getal[I] = 'C'  then dec_number := 12;
              if getal[I] = 'd'  then dec_number := 13;
              if getal[I] = 'D'  then dec_number := 13;
              if getal[I] = 'e'  then dec_number := 14;
              if getal[I] = 'E'  then dec_number := 14;
              if getal[I] = 'f'  then dec_number := 15;
              if getal[I] = 'F'  then dec_number := 15;

             uitvoer := uitvoer + (dec_number * trunc(Power(16, I-1)));
        end;
      hex2dec:=uitvoer;
    end;

 {
 This function gets a decimal number as an Integer and will return the octal number as a String
 }
function dec2oct(getal:Integer): String;
  var
  uitvoer: String;
  getal_met_rest : Real;
  begin
    while getal &amp;gt; 0 do
         begin
            getal_met_rest := getal / 8;
            uitvoer := uitvoer + IntToStr(getal - (trunc(getal_met_rest)*8));
            getal := trunc(getal_met_rest);
         end;
    dec2oct:=ReverseString(uitvoer);
  end;

 {
 This function gets octal number as a String and will return the decimamaal number as an Integer
 }
 function oct2dec(getal: String) : Integer;
    var
    uitvoer: Integer;
    I: Integer;
    begin
    uitvoer := 0;
    getal := ReverseString(getal);
      for I := 1 to length(getal) do
        begin
             uitvoer := uitvoer + (StrToInt(getal[I]) * trunc(Power(8, I-1)));
        end;
      oct2dec:=uitvoer;
    end;

&lt;/pre&gt;&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/pasprog/389747/429901/re-binary-to-decimal-and-decimal-to-binary-conversion/#429901</guid>
      <pubDate>Sun, 21 Oct 2012 09:32:21 -0700</pubDate>
      <category>Pascal</category>
    </item>
    <item>
      <title>Re: Binary to decimal and Decimal to binary conversion</title>
      <link>http://www.programmersheaven.com/mb/pasprog/389747/429902/re-binary-to-decimal-and-decimal-to-binary-conversion/#429902</link>
      <description>:))&lt;br /&gt;
&lt;pre class="sourcecode"&gt;
{Binary to decimal
This function gets binary number as a String and will return decimaal number as an Integer}
function bin2dec(getal:String): Integer;
  var
    I: Integer;
    uitvoer : Integer;
    begin
    uitvoer := 0;
      for I := 0 to length(getal) -1 do
        begin
          if getal[length(getal) - I] = '1' then
           begin
             uitvoer := uitvoer + 1 shl (I);
           end;
      end;
      bin2dec:=uitvoer;
  end;

{Returns a string in which the character order of a specified string is reversed}
function ReverseString(S : String): String;
      var
      i : Integer;
        begin
        Result := '';
        For i := Length(S) DownTo 1 Do
          Begin
            Result := Result + Copy(S,i,1) ;
          End;
      End;

  {
 Decimaal to binary
 This function gets a decimal number as Integer and will return the binary number as a String
}
function dec2bin(getal:Integer): String;
  var
  uitvoer:String;
  getal_met_rest : Real;
  begin
  while getal &amp;gt; 0 do
    begin
        getal_met_rest := getal / 2;
        if frac(getal_met_rest) = 0
          then uitvoer := uitvoer + '0'
          else uitvoer := uitvoer + '1';
        getal := trunc(getal_met_rest);
    end;
  dec2bin:=ReverseString(uitvoer);
  end;

 {
 This function gets a decimal number as an Integer and will return the HEX number as a String
 }
function dec2hex(getal:Integer): String;
  var
  uitvoer: String;
  getal_met_rest : Real;
  S : Integer;
  begin
    while getal &amp;gt; 0 do
         begin
            getal_met_rest := getal / 16;
            S := getal - (trunc(getal_met_rest)*16);
            if S &amp;lt; 10 then uitvoer := uitvoer + IntToStr(S);
            if S = 10 then uitvoer := uitvoer + 'A';
            if S = 11 then uitvoer := uitvoer + 'B';
            if S = 12 then uitvoer := uitvoer + 'C';
            if S = 13 then uitvoer := uitvoer + 'D';
            if S = 14 then uitvoer := uitvoer + 'E';
            if S = 15 then uitvoer := uitvoer + 'F';
            getal := trunc(getal_met_rest);
         end;
    dec2hex:=ReverseString(uitvoer);
  end;

  {
 This function gets hex number as a String and will return the decimamaal number as an Integer
 }
 function hex2dec(getal: String) : Integer;
    var
    uitvoer: Integer;
    I: Integer;
    dec_number: Integer;
    begin
    uitvoer := 0;
    getal := ReverseString(getal);
      for I := 1 to length(getal) do
        begin
              if getal[I] = '1'  then dec_number := 1;
              if getal[I] = '2'  then dec_number := 2;
              if getal[I] = '3'  then dec_number := 3;
              if getal[I] = '4'  then dec_number := 4;
              if getal[I] = '5'  then dec_number := 5;
              if getal[I] = '6'  then dec_number := 6;
              if getal[I] = '7'  then dec_number := 7;
              if getal[I] = '8'  then dec_number := 8;
              if getal[I] = '9'  then dec_number := 9;
              if getal[I] = 'a'  then dec_number := 10;
              if getal[I] = 'A'  then dec_number := 10;
              if getal[I] = 'b'  then dec_number := 11;
              if getal[I] = 'B'  then dec_number := 11;
              if getal[I] = 'c'  then dec_number := 12;
              if getal[I] = 'C'  then dec_number := 12;
              if getal[I] = 'd'  then dec_number := 13;
              if getal[I] = 'D'  then dec_number := 13;
              if getal[I] = 'e'  then dec_number := 14;
              if getal[I] = 'E'  then dec_number := 14;
              if getal[I] = 'f'  then dec_number := 15;
              if getal[I] = 'F'  then dec_number := 15;

             uitvoer := uitvoer + (dec_number * trunc(Power(16, I-1)));
        end;
      hex2dec:=uitvoer;
    end;

 {
 This function gets a decimal number as an Integer and will return the octal number as a String
 }
function dec2oct(getal:Integer): String;
  var
  uitvoer: String;
  getal_met_rest : Real;
  begin
    while getal &amp;gt; 0 do
         begin
            getal_met_rest := getal / 8;
            uitvoer := uitvoer + IntToStr(getal - (trunc(getal_met_rest)*8));
            getal := trunc(getal_met_rest);
         end;
    dec2oct:=ReverseString(uitvoer);
  end;

 {
 This function gets octal number as a String and will return the decimamaal number as an Integer
 }
 function oct2dec(getal: String) : Integer;
    var
    uitvoer: Integer;
    I: Integer;
    begin
    uitvoer := 0;
    getal := ReverseString(getal);
      for I := 1 to length(getal) do
        begin
             uitvoer := uitvoer + (StrToInt(getal[I]) * trunc(Power(8, I-1)));
        end;
      oct2dec:=uitvoer;
    end;

&lt;/pre&gt;&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/pasprog/389747/429902/re-binary-to-decimal-and-decimal-to-binary-conversion/#429902</guid>
      <pubDate>Sun, 21 Oct 2012 09:35:56 -0700</pubDate>
      <category>Pascal</category>
    </item>
    <item>
      <title>Re: Binary to decimal and Decimal to binary conversion</title>
      <link>http://www.programmersheaven.com/mb/pasprog/389747/429903/re-binary-to-decimal-and-decimal-to-binary-conversion/#429903</link>
      <description>:))))&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="sourcecode"&gt;

{Binary to decimal
This function gets binary number as a String and will return decimaal namber as an Integer}
function bin2dec(getal:String): Integer;
  var
    I: Integer;
    uitvoer : Integer;
    begin
    uitvoer := 0;
      for I := 0 to length(getal) -1 do
        begin
          if getal[length(getal) - I] = '1' then
           begin
             uitvoer := uitvoer + 1 shl (I);
           end;
      end;
      bin2dec:=uitvoer;
  end;

{Returns a string in which the character order of a specified string is reversed}
function ReverseString(S : String): String;
      var
      i : Integer;
        begin
        Result := '';
        For i := Length(S) DownTo 1 Do
          Begin
            Result := Result + Copy(S,i,1) ;
          End;
      End;

  {
 Decimaal to binary
 This function gets a decimal namber as Integer and will return the binary namber as a String
}
function dec2bin(getal:Integer): String;
  var
  uitvoer:String;
  getal_met_rest : Real;
  begin
  while getal &amp;gt; 0 do
    begin
        getal_met_rest := getal / 2;
        if frac(getal_met_rest) = 0
          then uitvoer := uitvoer + '0'
          else uitvoer := uitvoer + '1';
        getal := trunc(getal_met_rest);
    end;
  dec2bin:=ReverseString(uitvoer);
  end;

 {
 This function gets a decimal number as an Integer and will return the HEX number as a String
 }
function dec2hex(getal:Integer): String;
  var
  uitvoer: String;
  getal_met_rest : Real;
  S : Integer;
  begin
    while getal &amp;gt; 0 do
         begin
            getal_met_rest := getal / 16;
            S := getal - (trunc(getal_met_rest)*16);
            if S &amp;lt; 10 then uitvoer := uitvoer + IntToStr(S);
            if S = 10 then uitvoer := uitvoer + 'A';
            if S = 11 then uitvoer := uitvoer + 'B';
            if S = 12 then uitvoer := uitvoer + 'C';
            if S = 13 then uitvoer := uitvoer + 'D';
            if S = 14 then uitvoer := uitvoer + 'E';
            if S = 15 then uitvoer := uitvoer + 'F';
            getal := trunc(getal_met_rest);
         end;
    dec2hex:=ReverseString(uitvoer);
  end;

  {
 This function gets hex number as a String and will return the decimamaal number as an Integer
 }
 function hex2dec(getal: String) : Integer;
    var
    uitvoer: Integer;
    I: Integer;
    dec_number: Integer;
    begin
    uitvoer := 0;
    getal := ReverseString(getal);
      for I := 1 to length(getal) do
        begin
              if getal[I] = '1'  then dec_number := 1;
              if getal[I] = '2'  then dec_number := 2;
              if getal[I] = '3'  then dec_number := 3;
              if getal[I] = '4'  then dec_number := 4;
              if getal[I] = '5'  then dec_number := 5;
              if getal[I] = '6'  then dec_number := 6;
              if getal[I] = '7'  then dec_number := 7;
              if getal[I] = '8'  then dec_number := 8;
              if getal[I] = '9'  then dec_number := 9;
              if getal[I] = 'a'  then dec_number := 10;
              if getal[I] = 'A'  then dec_number := 10;
              if getal[I] = 'b'  then dec_number := 11;
              if getal[I] = 'B'  then dec_number := 11;
              if getal[I] = 'c'  then dec_number := 12;
              if getal[I] = 'C'  then dec_number := 12;
              if getal[I] = 'd'  then dec_number := 13;
              if getal[I] = 'D'  then dec_number := 13;
              if getal[I] = 'e'  then dec_number := 14;
              if getal[I] = 'E'  then dec_number := 14;
              if getal[I] = 'f'  then dec_number := 15;
              if getal[I] = 'F'  then dec_number := 15;

             uitvoer := uitvoer + (dec_number * trunc(Power(16, I-1)));
        end;
      hex2dec:=uitvoer;
    end;

 {
 This function gets a decimal number as an Integer and will return the octal number as a String
 }
function dec2oct(getal:Integer): String;
  var
  uitvoer: String;
  getal_met_rest : Real;
  begin
    while getal &amp;gt; 0 do
         begin
            getal_met_rest := getal / 8;
            uitvoer := uitvoer + IntToStr(getal - (trunc(getal_met_rest)*8));
            getal := trunc(getal_met_rest);
         end;
    dec2oct:=ReverseString(uitvoer);
  end;

 {
 This function gets octal number as a String and will return the decimamaal number as an Integer
 }
 function oct2dec(getal: String) : Integer;
    var
    uitvoer: Integer;
    I: Integer;
    begin
    uitvoer := 0;
    getal := ReverseString(getal);
      for I := 1 to length(getal) do
        begin
             uitvoer := uitvoer + (StrToInt(getal[I]) * trunc(Power(8, I-1)));
        end;
      oct2dec:=uitvoer;
    end;

&lt;/pre&gt;&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/pasprog/389747/429903/re-binary-to-decimal-and-decimal-to-binary-conversion/#429903</guid>
      <pubDate>Sun, 21 Oct 2012 09:44:33 -0700</pubDate>
      <category>Pascal</category>
    </item>
  </channel>
</rss>