Flash Website Builder- Trendy Site Builder is a Flash Site Building tool that helps users build stunning websites. Check Out Custom Custom Logo Design by LogoBee. Website Design and Free Logo Templates available.
 CodingForums.com Binary div in C/C++
 User Name Remember Me? Password

Before you post, read our: Rules & Posting Guidelines

Enjoy an ad free experience by logging in. Not a member yet? Register.
 03-07-2007, 03:58 AM PM User | #1 klam New Coder   Join Date: Jan 2007 Posts: 12 Thanks: 1 Thanked 0 Times in 0 Posts Binary div in C/C++ Hey there, I'm having a hard time coming out with a binary div function. I'm using this pseudocode as my guide: Code: ``` function crc(bit array bitString[1..len+n], int len) { remainderPolynomial := polynomialForm(bitString[1..n]) // First n bits of the message // A popular variant complements remainderPolynomial here for i from 1 to len { remainderPolynomial := remainderPolynomial * x + bitString[i+n] * x0 if coefficient of xn of remainderPolynomial = 1 { remainderPolynomial := remainderPolynomial xor generatorPolynomial } } // A popular variant complements remainderPolynomial here return remainderPolynomial }``` can someone come up with an implementation? This is for a cyclicRedundancyCheck (all in all, all i'd like is 2 binary nums divided). I'm aware that binary division are done by shifting and xoring, can anyone come up with a better idea? EDITED: Well I decided that was too complicated so I did it in a different manner... Last edited by klam; 03-07-2007 at 09:54 PM.. Reason: Solved.
 03-07-2007, 10:04 PM PM User | #2 ralph l mayo Regular Coder     Join Date: Nov 2005 Posts: 951 Thanks: 1 Thanked 31 Times in 29 Posts Is this cheating? Code: ```#include #include using namespace std; class DivisionByZeroError {}; template inline bitset operator/(const bitset& numerator, const bitset& denominator) { if (denominator.none()) { throw DivisionByZeroError(); } return numerator.to_ulong()/denominator.to_ulong(); } int main(int, char**) { static const unsigned MAX_BIT_LEN = 16; bitset b1 = 32; bitset b2 = 4; cout << b1 << "/" << b2 << " = " << b1 / b2; return 0; }``` Last edited by ralph l mayo; 03-07-2007 at 10:52 PM.. Reason: More complete example with syntactic sugar. Same issue-dodging core.

 Bookmarks

 Thread Tools Rate This Thread Rate This Thread: 5 : Excellent 4 : Good 3 : Average 2 : Bad 1 : Terrible

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home :: Client side development     JavaScript programming         DOM and JSON scripting         Ajax and Design         JavaScript frameworks         Post a JavaScript     HTML & CSS     XML     Flash & ActionScript         Adobe Flex     Graphics and Multimedia discussions     General web building         Site reviews         Building for mobile devices :: Server side development     Apache configuration     Perl/ CGI     PHP         Post a PHP snippet     MySQL         Other Databases     Ruby & Ruby On Rails     ASP     ASP.NET     Java and JSP     Other server side languages/ issues         ColdFusion         Python :: Computing & Sciences     Computer Programming     Computer/PC discussions     Geek News and Humour Web Projects and Services Marketplace     Web Projects         Small projects (quick fixes and changes)         Medium projects (new script, new features, etc)         Large Projects (new web application, complex features etc)         Unknown sized projects (request quote)         Vacant job positions         Looking for work/ for hire         Project collaboration/ partnership         Paid work offers and requests (Now CLOSED)     Career, job, and business ideas or advice     Domains, Sites, and Designs for sale         Domains for sale         Websites for sale         Design templates and graphics for sale :: Other forums     Member Offers     Forum feedback and announcements

All times are GMT +1. The time now is 08:10 AM.