?
Solved

C# Funtion Calculating UTF-8 BCC

Posted on 2010-08-26
3
Medium Priority
?
1,285 Views
Last Modified: 2013-12-17
Hello guys,
I have a string and convert it into UTF-8 byte array, so this array needs to be an parameter of a function, that will return the BCC. But I need the function.
0
Comment
Question by:IncognitoMan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
3 Comments
 
LVL 4

Accepted Solution

by:
ricovox earned 2000 total points
ID: 33535695
Hello,

I believe by BCC you mean byte,block, and checksum, right?
Can you tell me a little more about the way your data is formatted?

What I mean is that usually you send the data in a transmission that includes additional information like this:
<data...><additional bytes><checksum>

Where "additional bytes" are 1 or 2 additional random bytes that you add to the transmission to ensure better verification accuracy. These would be optional, and maybe you have them and maybe you don't. It depends on your application.

Usually you want to compare the calculated checksum of the data plus the additional bytes AFTER transmission with the checksum calculated BEFORE transmission. Does this sound about right? Do you use the additional bytes or not?

I don't know if the definition for BCC is standardized, but I saw an 8-bit BCC calculated by XORing all the bytes in the data:

private byte CalcBCC(byte[] buffer)
{
    byte calc = 0x00;
   
    //XOR with each byte in the buffer
    for (int i = 1; i < buffer.Length - 1; i++)
    {
        calc ^= buffer[i];
    }
    return calc;
}

You would just have to be consistent in using the same function both before and after transmission to obtain the same checksum. Also make sure to be consistent with what part of the datastream you calculate. I.e. if there are "additional bytes" then make sure to include them in both calculations for consistency.

Hope that helps.
0
 
LVL 4

Expert Comment

by:ricovox
ID: 33535827
After more searching I found another reference about BCC.
This is a PDF that is probably for a specific RS232 instrument.
http://www.bttautomatyka.com.pl/pdf/HA466357.pdf

In it, they have data formatted like this:
<STX><DATA><ETX><CHECKSUM>
Where STX and ETX are each single bytes representing the start and end of the data, respectively.
The BCC is calculated exactly as I specified in the code in my previous post, but it INCLUDES both the STX and ETX. So you have to make sure that these are included in the byte array you pass in to the function. Then you have to remember that the data does NOT include these two characters. The data also does not include the checksum at the end, which is another single byte.

I can send you some more code if you need additional help.
0
 
LVL 4

Expert Comment

by:ricovox
ID: 33535834
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
When there is a disconnect between the intentions of their creator and the recipient, when algorithms go awry, they can have disastrous consequences.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question