Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19
Question: Bits and C++
Results 1 to 10 of 10

Thread: Question: Bits and C++

  1. #1
    Guest

    Question: Bits and C++

    Okay.. here's the question - what's the easist way of making an XOR checksum byte for a string.

    I would think some think like this:

    Code:
    int hold;
    int checksum = string[0];
    for(int i=1, i > strlen(string)-1, i++)
    {
    hold = checksum;
    checksum = string[i] ^ hold;
    }
    Problem - ^ is a bitwise operator and a byte is 8 bits, and we need the result of xoring the bytes indidually not the bits indvidually.

    I figured that Xoring the string and appending my checksum as an int, cast as a char - it should be safe as the int never will be bigger then the byte can hold.

    (I have to convert my ints to chars to be able to use them futher on in my system - I'll post the entire code later for you guys to laugh at)

    basic idea:

    Pack string in HDLC compliant format, send to external unit,

    string -> stick - DLE, STX, Adresse of external unit, Control field (will be a bitfield), ID, PAYLOAD (our string), ETX and Checksum. -> HEY HO... off to I/O we go..

  2. #2

    Re: Question: Bits and C++

    I'm confused as to what you mean by XORing a byte, if not bit by bit.

  3. #3

    Re: Question: Bits and C++

    Why not dump the individual chars into a vector? Or make a class for the correct output? Of course, I'm still fuzzy on what you are trying to do...

  4. #4
    Guest

    Re: Question: Bits and C++

    No problem, I think I got a solution which is much cleaner.

    Just need to debug the code a bit.

  5. #5

    Re: Question: Bits and C++

    If your complaint is about using a 16-bit integer to make checksums byte by byte, then don't use an integer. Use another char.

  6. #6
    Guest

    Re: Question: Bits and C++


    If your complaint is about using a 16-bit integer to make checksums byte by byte, then don't use an integer. Use another char.
    oh no... if had to choose I wouldn't even do it XOR style... I would use a proper CRC16/32 checksum, the assignment requires me to use one char XOR checksum - 8 bits. If I don't do that I'll break protocol and my project group will kill me...

  7. #7

    Re: Question: Bits and C++


    oh no... if had to choose I wouldn't even do it XOR style... I would use a proper CRC16/32 checksum, the assignment requires me to use one char XOR checksum - 8 bits. If I don't do that I'll break protocol and my project group will kill me...
    Well then my suggestion should be fitting.

  8. #8
    Guest

    Re: Question: Bits and C++




    Well then my suggestion should be fitting.
    Oh I am using a char, sorry for the mix up.

    doh did I just write int in my code ex..... stupid me...

  9. #9

    Re: Question: Bits and C++

    Just a question, ive had some C++ but what do you mean by XORing a byte not bit by bit? How do you XOR a whole byte? Isnt it essentially doing it bit by bit no matter what?

  10. #10
    Guest

    Re: Question: Bits and C++


    Just a question, ive had some C++ but what do you mean by XORing a byte not bit by bit? How do you XOR a whole byte? Isnt it essentially doing it bit by bit no matter what?
    No worries, seems I got the protocol design wrong, my friend corrected it and I'll post his code tomorrow. He's code is much cleaner than mine, but I suspect he had help from our local C++ guru... Which really is cheating (when I do it it's clever... )

Similar Threads

  1. Sampling bits of information
    By Smegma in forum Linux - General Topics
    Replies: 0
    Last Post: 10-29-2003, 11:25 AM
  2. Doing stuff to bits in C++??
    By in forum Linux - Software, Applications & Programming
    Replies: 4
    Last Post: 12-05-2002, 01:14 AM
  3. Tid-Bits #2- CVS
    By babbing in forum Linux - General Topics
    Replies: 6
    Last Post: 10-30-2002, 08:32 PM
  4. Tid-Bits #3- Setting Permissions
    By babbing in forum Linux - General Topics
    Replies: 8
    Last Post: 10-29-2002, 05:42 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •