473,668 Members | 2,373 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to exchange 1234(number) -> bytes sequence

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

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.GetByteCoun t( chars );

but i want to make interger value to byte[].
"Bruce Wood" <br*******@cana da.comwrote in message
news:11******** *************@1 6g2000cwy.googl egroups.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.ToS tring("x2"));
}
Debug.WriteLine (sb, caption);
}
static void Main()
{
WriteHex("Encod ing", Encoding.UTF8.G etBytes("1234") );
WriteHex("BitCo nverter", BitConverter.Ge tBytes(1234));

}

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

BitConverter.Ge tBytes(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
6162
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
5270
by: Davey | last post by:
How do I display an integer in binary format in C? e.g. 4 displayed as "100"
1
1288
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 formatted @@-@@@@. The results are 0-61234 in the combo box. Can you assist me? Thank you Charlie -- Message posted via http://www.accessmonster.com
1
3941
by: Gerhard | last post by:
How can I create a new contact in exchange server from a vb.net web application?
1
1585
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 the code for the results page that shows the barcodes to print: <%
1
1940
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 some basic info on our structure. - Domain/Forest A with Exchange - Domain/Forest B with external accounts. - Forest A Trus Forest B and "Vice Versa" - asp page on a Exchange FrontEnd server on default web site (same as
0
1644
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 1 1234 789 2 1234 567 1 1234 345 1 I would like sale_no auto generated based on resv and locn, without using a trigger. Is this possible?
8
1741
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 FROM OLD BROWSERS
4
4214
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 do it in C# Below is what I am trying to di number = 123 I want it to be
0
1005
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 Exchange server release Exchange server OS OS service packs installed - currently doing so. Exchange service packs install
0
8459
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8378
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8890
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8577
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8653
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6206
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4202
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2786
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1783
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.