473,385 Members | 1,817 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,385 software developers and data experts.

how to exchange 1234(number) -> bytes sequence

how to exchange 1234(number) -bytes sequence in the C#?
Dec 4 '06 #1
4 2061

penzer wrote:
how to exchange 1234(number) -bytes sequence in the C#?
What do you mean by "bytes sequence"?

Do you mean take the 32-bit integer value 1234 and change it to an
array of 4 bytes, each containing 8 of the bits of the original 32-bit
value?

Or do you mean formatting the integer value 1234 as a printable string?
(This one is easy: just call ToString() on the value, or use
String.Format("{0}", 1234);)

Or do you mean something else?

It would help if you would describe the expected output in more detail
than simply "bytes sequence".

Dec 4 '06 #2
I mean I want to encode 32-bit integer value to byte sequence.

example,
char [] chars = "abcd"
int iBC = enc.GetByteCount( chars );

but i want to make interger value to byte[].
"Bruce Wood" <br*******@canada.comwrote in message
news:11*********************@16g2000cwy.googlegrou ps.com...
>
penzer wrote:
>how to exchange 1234(number) -bytes sequence in the C#?

What do you mean by "bytes sequence"?

Do you mean take the 32-bit integer value 1234 and change it to an
array of 4 bytes, each containing 8 of the bits of the original 32-bit
value?

Or do you mean formatting the integer value 1234 as a printable string?
(This one is easy: just call ToString() on the value, or use
String.Format("{0}", 1234);)

Or do you mean something else?

It would help if you would describe the expected output in more detail
than simply "bytes sequence".

Dec 4 '06 #3
CLR char types are 16 bit, so your example is duff.

It would *really* help your example if you told us the expected outcome.
People have indicated that your question is vague: it really is!

So: do you mean the **string** "1234" as a byte[] of the (encoded) character
data (Encoding)? Or perhaps you mean the bytes that make up an integer
(BitConverter); anyways - do these help?

static void WriteHex(string caption, byte[] data)
{
StringBuilder sb = new StringBuilder();
foreach(byte b in data) { // possibly backwards; quick demo only
sb.Append(b.ToString("x2"));
}
Debug.WriteLine(sb, caption);
}
static void Main()
{
WriteHex("Encoding", Encoding.UTF8.GetBytes("1234"));
WriteHex("BitConverter", BitConverter.GetBytes(1234));

}

Output:
Encoding: 31323334
BitConverter: d2040000
Dec 4 '06 #4

BitConverter.GetBytes(int)

HTH,

Sam
------------------------------------------------------------
We're hiring! B-Line Medical is seeking Mid/Sr. .NET
Developers for exciting positions in medical product
development in MD/DC. Work with a variety of technologies
in a relaxed team environment. See ads on Dice.com.

On Mon, 4 Dec 2006 16:31:47 +0900, "penzer" <pe******@gmail.com>
wrote:
>how to exchange 1234(number) -bytes sequence in the C#?
Dec 4 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: johkar | last post by:
How do I ensure a number has no more than 4 digits and 2 decimal places (adds .0 or .00 as necessary) onblur using reg expressions? Hints or solutions appreciated. John
23
by: Davey | last post by:
How do I display an integer in binary format in C? e.g. 4 displayed as "100"
1
by: hireagenius | last post by:
Hi heros, I have a text field that stores numbers like 06-1234. I created a combo box to look up values on a form based on the number. However, I can't get it formatted correctly. It is...
1
by: Gerhard | last post by:
How can I create a new contact in exchange server from a vb.net web application?
1
by: Mangler | last post by:
I dont know if this is possible or if someone has a better way to do this but here it is: I have a page where the user enters an rma#, lot#, and number of barcodes they need to print, here is...
1
by: ouistyty | last post by:
Hi We have a simple asp page that query LDAP attribrute. Everithing is working fine using a native domain account. but when using an external account we have an error 70, acces denie. Here's...
0
barbk
by: barbk | last post by:
Hey all, In DB2 v9 is it possible to have an auto generated number field within a primary key that is a combination of multiple fields? For example resv locn sale_no 1234 789...
8
by: Brigitte Behrmann | last post by:
The question goes like this: The following code contains errors, find and correct the errors. <html> <head> <title>Project2-3</title> </head> <body> <SCRIPT LANGUAGE="JavaScript"> <!--HIDE...
4
by: =?Utf-8?B?Vmlua2k=?= | last post by:
Hello Everyone, I am trying to convert the digits to even number so for example if I have 3 digit number, I want it to be 4 digit and If I have 5 digit number, I want it to be 6 digit. How can i...
0
by: =?Utf-8?B?YXVsZGg=?= | last post by:
hello i need some assistance on how to start on this project. i was given a very large wish list to collect from and Exchange environment. Exchange name LDAP server name Exchange IP address...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...

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.