please dont rip this site

Language Ccpp Cref Problems Binary_op.c

/ ************************************************************************
 *
 * Purpose: Display a byte in binary format.
 * 
 * Author:  M.J. Leslie.
 *
 * Date:    19-Mar-95
 *
 * Improvements: 
 *	1) Return the result to the calling function.
 *	2) Make it work on integers (4 bytes long).
 *
 ************************************************************************/

void binary_op(char byte);		/* Print a byte in binary.	*/

/************************************************************************/

main()
   {
   char byte=55;	

   binary_op(byte);			/* Print a byte in binary.	*/
   }

/************************************************************************/

void binary_op(char byte)
   {
   int count=8;				/* Number of bits in a byte.	*/

   while(count--)
      {
					/* AND the high order bit (the
					 * left one) If the bit is set,
					 * print a ONE.			*/
      printf("%d", ( byte & 128 ) ? 1 : 0 );

					/* Move all the bits LEFT.	*/
      byte <<= 1;
      } 

   printf("\n");
   }

/************************************************************************
 *
 *	Program results.
 *	----------------
 *
 *	00110111
 *
 ************************************************************************/


file: /Techref/language/ccpp/cref/PROBLEMS/binary_op.c, 1KB, , updated: 1997/4/21 09:53, local time: 2024/5/4 07:13,
TOP NEW HELP FIND: 
18.223.114.142:LOG IN

 ©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?
Please DO link to this page! Digg it! / MAKE!

<A HREF="http://piclist.com/techref/language/ccpp/cref/PROBLEMS/binary_op.c"> language ccpp cref PROBLEMS binary_op</A>

Did you find what you needed?

  PICList 2024 contributors:
o List host: MIT, Site host massmind.org, Top posters @none found
- Page Editors: James Newton, David Cary, and YOU!
* Roman Black of Black Robotics donates from sales of Linistep stepper controller kits.
* Ashley Roll of Digital Nemesis donates from sales of RCL-1 RS232 to TTL converters.
* Monthly Subscribers: Gregg Rew. on-going support is MOST appreciated!
* Contributors: Richard Seriani, Sr.
 

Welcome to piclist.com!

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  .