473,396 Members | 1,995 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to convert a int to 4 byte (DWORD) hex values

A graphics company requires that the byte count of a string I need to be build be included in the message sent to it. I am building the message like this..

Expand|Select|Wrap|Line Numbers
  1. string StartBytes = "" + (char)STX + (char)0x00 + (char)0x00 + (char)0x00 + (char)TotalByteCount + (char)Command;
  2. string EndBytes = "" + (char)0x00 + (char)0x00 + (char)0x00 + (char)TotalByteCount + (char)ETX;
  3.  
  4. string SendMsg = StartBytes.Trim() + ObjectList.Trim() + EndBytes.Trim();
The four chars after the STX needs to represent the total byte count.
In documentation, they show this as ...

BC (Byte Count): Packet total size including Start Code and End Code
Transmit in DWORD (4byte) type

Ex) Packet size = 0x00001234
0x00
0x00
0x12
0x34
I am building this all as a string and using the following to convert to bytes..
Expand|Select|Wrap|Line Numbers
  1. byte[] bytesSendMsg = new byte[SendMsg.Length];
  2. bytesSendMsg = ASCIIEncoding.ASCII.GetBytes(SendMsg);
SendMsg is my string that I build...

Appreciate any help any one can provide.
Oct 7 '10 #1
1 5263
Frinavale
9,735 Expert Mod 8TB
What exactly is the problem?
Are you experiencing errors?
Is the output not as you expect it?

-Frinny
Oct 7 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

16
by: Khuong Dinh Pham | last post by:
I have the contents of an image of type std::string. How can I make a CxImage object with this type. The parameters to CxImage is: CxImage(byte* data, DWORD size) Thx in advance
4
by: John Smith | last post by:
Hello, Suppose I have the following C# code which I want to convert to VB: for (int i = 0; i < nFieldLength; i++) Console.Write((char) sValue); sValue is a byte array. The problem is...
6
by: moondaddy | last post by:
I'm writing an app in vb.net 1.1 and need to convert a byte array into a string, and then from a string back to a byte array. for example Private mByte() as New Byte(4){11,22,33,44} Now how...
2
by: Tedmond | last post by:
Can anyone tell me how to convert a byte to bit pattern? e.g. Byte b = 1; after conversion = 00000001 Tedmond
3
by: Elezar Simeon Papo | last post by:
Hello All, I have a tab separated input file (data.txt) in text format - the file looks like this SCHOOL DEPART1 DEPART2 DEPART3 Harvard Economics Mathematics Physics...
2
by: ElizaInternet | last post by:
I need convert NITF Xmls for insert into BD SQL. I try convert to file text and then insert into BD I used the Syndication:NITF of perl for this convertion. Any have information about this??, I...
6
by: | last post by:
Hi, How do I convert a byte to an object? I am trying to use IADs PutEx and the last parameter required a variant array. Thanks, Alex
10
by: =?Utf-8?B?Um95?= | last post by:
What is the way to have best performance to copy a byte to a value such as long? I use BitConverter.ToInt64(binary, offset) But the performace is not good enough. I need to have the best...
6
by: Bob Altman | last post by:
Hi all, I'm looking for the fastest way to convert an array of bytes to String. I also need to convert a String back to its original Byte() representation. Convert.ToBase64String and...
18
by: MrVS | last post by:
Hi, I have a C++ CLR class method that takes System::Byte *b as parameter argument. I want the CSharp caller pass a byte * to this function. But in the CSharp prorgram, I only managed to create a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.