program binary

program binary

Hi

I want to write a program in pascal that ask a user to input a decimal number and then return its binary equivalent in the minimum number of bits required to repesent the number. In pascal language please

Thks

View Answers

June 24, 2011 at 10:39 AM

Try this:

program decimalToBinary;

const v: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[(v[i] and b=v[i])];
  dec2bin:=s;
 end;

June 29, 2011 at 10:47 PM

Many Thanks

Will try it

Rgds

Ads









Related Tutorials/Questions & Answers:
program binary
program binary  Hi I want to write a program in pascal that ask a user to input a decimal number and then return its binary equivalent in the minimum number of bits required to repesent the number. In pascal language please
binary search program
binary search program  write a program to searching a string using binary search
Advertisements
binary search program
binary search program  write a program to searching a string using binary search
binary search program
binary search program  write a program to searching a string using binary search
binary search program
binary search program  write a program to searching a string using binary search
binary search program
binary search program  write a program to searching a string using binary search
swing program for decimal to binary
swing program for decimal to binary  swing program for decimal to binary
Write a program in Java to convert Decimal number into Binary number
Write a program in Java to convert Decimal number into Binary number  Hi, I have decimal number and I want to convert it to Binary. How to Write a program in Java to convert Decimal number into Binary number? Thanks
binary
binary  Hi I want to write a program in pascal that ask a user to input a decimal number and then return its binary equivalent in the minimum number of bits required to repesent the number. Thks
Convert Text to Binary
Convert Text to Binary       In this section, we will learn how to convert Text to Binary. The following program provides you the functionality to convert Text to Binary
Convert Text to Binary
to Binary. The following program provides you the functionality to convert Text to Binary. Code Description: In the program code below, to take the input from... Convert Text to Binary      
Binary tree
Binary tree  a. Construct a method to implement a binary tree using an array. b. Implement the binary tree to store numbers in sorted order
ModuleNotFoundError: No module named 'binary'
ModuleNotFoundError: No module named 'binary'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'binary' How to remove the ModuleNotFoundError: No module named 'binary'
binary tree
binary tree  can a binary tree be implemented with out comparing...://www.roseindia.net/java/java-get-example/java-binary-tree-code.shtml http://www.roseindia.net/java/java-get-example/java-binary-tree-insert.shtml
binary tree
binary tree  how to count no. of nodes in a binary tree for mlm if it complet tree or incomplet tree in php using mysql db
octal to binary
octal to binary  i want to know how to convert a octal to binary number   Here is a java example that converts octal to binary. import... binary=Integer.toBinaryString(i); System.out.println(binary
ModuleNotFoundError: No module named 'binary_clock'
ModuleNotFoundError: No module named 'binary_clock'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'binary_clock' How to remove the ModuleNotFoundError: No module named '
ModuleNotFoundError: No module named 'binary-heap'
ModuleNotFoundError: No module named 'binary-heap'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'binary-heap' How to remove the ModuleNotFoundError: No module named '
ModuleNotFoundError: No module named 'binary-refinery'
ModuleNotFoundError: No module named 'binary-refinery'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'binary-refinery' How to remove the ModuleNotFoundError: No module named
ModuleNotFoundError: No module named 'binary-search'
ModuleNotFoundError: No module named 'binary-search'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'binary-search' How to remove the ModuleNotFoundError: No module named
ModuleNotFoundError: No module named 'binary-to-string'
ModuleNotFoundError: No module named 'binary-to-string'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'binary-to-string' How to remove the ModuleNotFoundError: No module
ModuleNotFoundError: No module named 'binary-tree'
ModuleNotFoundError: No module named 'binary-tree'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'binary-tree' How to remove the ModuleNotFoundError: No module named '
ModuleNotFoundError: No module named 'chromedriver-binary'
ModuleNotFoundError: No module named 'chromedriver-binary'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'chromedriver-binary' How to remove the ModuleNotFoundError
ModuleNotFoundError: No module named 'dataclasses-binary'
ModuleNotFoundError: No module named 'dataclasses-binary'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'dataclasses-binary' How to remove the ModuleNotFoundError: No module
ModuleNotFoundError: No module named 'fortran-binary'
ModuleNotFoundError: No module named 'fortran-binary'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'fortran-binary' How to remove the ModuleNotFoundError: No module named
ModuleNotFoundError: No module named 'phantomjs-binary'
ModuleNotFoundError: No module named 'phantomjs-binary'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'phantomjs-binary' How to remove the ModuleNotFoundError: No module
ModuleNotFoundError: No module named 'prison-no-binary'
ModuleNotFoundError: No module named 'prison-no-binary'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'prison-no-binary' How to remove the ModuleNotFoundError: No module
ModuleNotFoundError: No module named 'pycopy-binary'
ModuleNotFoundError: No module named 'pycopy-binary'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'pycopy-binary' How to remove the ModuleNotFoundError: No module named
ModuleNotFoundError: No module named 'talib-binary'
ModuleNotFoundError: No module named 'talib-binary'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'talib-binary' How to remove the ModuleNotFoundError: No module named '
ModuleNotFoundError: No module named 'yxspkg_binary'
ModuleNotFoundError: No module named 'yxspkg_binary'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'yxspkg_binary' How to remove the ModuleNotFoundError: No module named
ModuleNotFoundError: No module named 'attrs-binary'
ModuleNotFoundError: No module named 'attrs-binary'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'attrs-binary' How to remove the ModuleNotFoundError: No module named '

Ads