473,399 Members | 3,888 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,399 software developers and data experts.

How to convert int to byte[]

How can we convert the integer values to byte arrays using C#.NET
Nov 16 '05 #1
7 2425
Encoding.UTF8.GetBytes(i.ToString());

Av.

http://dotnetjunkies.com/WebLog/avnrao
http://www28.brinkster.com/avdotnet
"Shankar" <Sh*****@discussions.microsoft.com> wrote in message
news:E6**********************************@microsof t.com...
How can we convert the integer values to byte arrays using C#.NET

Nov 16 '05 #2
Shankar <Sh*****@discussions.microsoft.com> wrote:
How can we convert the integer values to byte arrays using C#.NET


Depending on exactly what you want, BitConverter is usually the way to
go.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #3
avnrao <av*@newsgroups.com> wrote:
Encoding.UTF8.GetBytes(i.ToString());


While that will indeed convert an int into an array of bytes, I'm not
sure it's likely to be the format the OP is looking for - I suspect
BitConverter is more likely to be useful.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #4
Yes, it was useful. But again i got one problem of using this UTF8

1. I have one string that i'm encrypting and getiing byte[]
but in SQL data base i have the field type varchar for that one i converting
that
byte[] to string and storing database. when I'm going to Decrypt that string
i'm getting length problem.

guide me in this regard.
"Jon Skeet [C# MVP]" wrote:
Shankar <Sh*****@discussions.microsoft.com> wrote:
How can we convert the integer values to byte arrays using C#.NET


Depending on exactly what you want, BitConverter is usually the way to
go.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #5
shankar <sh*****@discussions.microsoft.com> wrote:
Yes, it was useful. But again i got one problem of using this UTF8

1. I have one string that i'm encrypting and getiing byte[]
but in SQL data base i have the field type varchar for that one i converting
that
byte[] to string and storing database. when I'm going to Decrypt that string
i'm getting length problem.


Are you trying to convert the byte[] to a string just by using
Encoding.UTF8.GetString()? You shouldn't - you should use base 64 to
convert *arbitrary* binary data to a string and back again. See
Convert.ToBase64String and Convert.FromBase64String.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #6
tes

From http://www.developmentnow.com/g/36_2...int-to-byte.ht

Posted via DevelopmentNow.com Group
http://www.developmentnow.com
Nov 17 '05 #8

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

Similar topics

19
by: jeff | last post by:
how do you convert form byte to Int32 while retaining the binary value of the byte array
1
by: Swarup | last post by:
I am reading a file (txt, xml, gif, ico, bmp etc) byte by byte and filling it into a byte arry. Now i have to convert it into a string to store it in the database. I use...
6
by: Ricardo Quintanilla | last post by:
i have a code that sends data to a socket listening over as400 platform, the socket responds to me as a "byte array". then i need to convert the "byte array" into a string. the problem is that...
3
by: MuZZy | last post by:
Hi, I just wonder if someone can help me wit this - i have a byte array and need to convert it to short array, creating short numbers by combining bytes by pairs: My array: byte, byte, byte,...
25
by: Charles Law | last post by:
I thought this was going to be straight forward, given the wealth of conversion functions in .NET, but it is proving more convoluted than imagined. Given the following <code> Dim ba(1) As...
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...
65
by: kyle.tk | last post by:
I am trying to write a function to convert an ipv4 address that is held in the string char *ip to its long value equivalent. Here is what I have right now, but I can't seem to get it to work. ...
5
by: Bob Homes | last post by:
In VB6, foreground and background colors of controls had to be assigned a single number. If you knew the RGB values for the color, you still had to convert them into the single number accepatable...
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...
0
Debadatta Mishra
by: Debadatta Mishra | last post by:
Introduction In this article I will provide you an approach to manipulate an image file. This article gives you an insight into some tricks in java so that you can conceal sensitive information...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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,...
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
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...
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,...
0
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...

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.