please dont rip this site

C++ Programming Example

Convert to Binary

Converts a character or string into a binary string (a string of "0" or "1";s). The use of std::string removes any need for dynamic allocation and pointer maintenance. From:
http://www.experts-exchange.com/Programming/Programming_Languages/Cplusplus/Q_20525179.html

#include <string>
using namespace std;

string Byte2Binary(unsigned char c) {
string S;
unsigned char Msk = 0x80;

	for (int i = 0; i < 8; ++i) {
		if (c & Msk) S += '1';
		else S += '0';
		Msk >>= 1;
		}
	return S;
	}

string String2Binary(const string &S) {
const int StrLen = S.length();
string Result;

	for (int i = 0; i < StrLen; ++i)
		Result  += Byte2Binary(unsigned char) S[i]);
	return Result;
	}


file: /Techref/language/ccpp/cppref/EXAMPLES/2binary_cc.htm, 1KB, , updated: 2006/3/31 16:37, local time: 2024/4/26 22:29,
TOP NEW HELP FIND: 
3.133.79.70: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://techref.massmind.org/techref/language/ccpp/cppref/EXAMPLES/2binary_cc.htm"> C++ Programming Example Convert to Binary</A>

After you find an appropriate page, you are invited to your to this massmind site! (posts will be visible only to you before review) Just type a nice message (short messages are blocked as spam) in the box and press the Post button. (HTML welcomed, but not the <A tag: Instead, use the link box to link to another page. A tutorial is available Members can login to post directly, become page editors, and be credited for their posts.


Link? Put it here: 
if you want a response, please enter your email address: 
Attn spammers: All posts are reviewed before being made visible to anyone other than the poster.
Did you find what you needed?

 

Welcome to massmind.org!

 

Welcome to techref.massmind.org!

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  .