473,466 Members | 1,661 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Long to array of bytes

Jan
How can I convert Long value to array of bytes?

Nov 19 '05 #1
4 11877
Dim MyLong As Long = 55695542

Dim msg As Byte() = System.Text.Encoding.ASCII.GetBytes(MyLong)

CW

"Jan" <js***@nemtru.cz> wrote in message
news:0b****************************@phx.gbl...
How can I convert Long value to array of bytes?

Nov 19 '05 #2
Jan
Thank you, but I need convert into binary (memory) form.
I need only 4 bytes in result.

ex: long value 55695542 -->

arr(0) == &HB6
arr(1) == &HD8
arr(2) == &H51
arr(3) == &H03

Please, can you give me advise

Thank you
-----Original Message-----
Dim MyLong As Long = 55695542

Dim msg As Byte() = System.Text.Encoding.ASCII.GetBytes (MyLong)
CW

"Jan" <js***@nemtru.cz> wrote in message
news:0b****************************@phx.gbl...
How can I convert Long value to array of bytes?

.

Nov 19 '05 #3

Hi Jan,

I think you can use Shift Operators to get certain bit.

HTH.
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
| Content-Class: urn:content-classes:message
| From: "Jan" <js***@nemtru.cz>
| Sender: "Jan" <js***@nemtru.cz>
| References: <0b****************************@phx.gbl>
<#1**************@tk2msftngp13.phx.gbl>
| Subject: Re: Long to array of bytes
| Date: Fri, 22 Aug 2003 01:48:02 -0700
| Lines: 32
| Message-ID: <08****************************@phx.gbl>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="iso-8859-1"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Thread-Index: AcNoihjXyOTjNSzbSgu/vIw5YOe8rA==
| X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
| Newsgroups: microsoft.public.dotnet.languages.vb
| Path: cpmsftngxa06.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:129629
| NNTP-Posting-Host: TK2MSFTNGXA14 10.40.1.166
| X-Tomcat-NG: microsoft.public.dotnet.languages.vb
|
| Thank you, but I need convert into binary (memory) form.
| I need only 4 bytes in result.
|
| ex: long value 55695542 -->
|
| arr(0) == &HB6
| arr(1) == &HD8
| arr(2) == &H51
| arr(3) == &H03
|
| Please, can you give me advise
|
| Thank you
|
| >-----Original Message-----
| >Dim MyLong As Long = 55695542
| >
| >Dim msg As Byte() = System.Text.Encoding.ASCII.GetBytes
| (MyLong)
| >
| >
| >
| >CW
| >
| >"Jan" <js***@nemtru.cz> wrote in message
| >news:0b****************************@phx.gbl...
| >> How can I convert Long value to array of bytes?
| >>
| >
| >
| >.
| >
|

Nov 19 '05 #4
Hello,

"Jan" <js***@nemtru.cz> schrieb:
How can I convert Long value to array of bytes?


\\\
Dim abyt() As Byte = BitConverter.GetBytes(CLng(12345))
///

HTH,
Herfried K. Wagner
--
MVP · VB Classic, VB .NET
http://www.mvps.org/dotnet
Nov 19 '05 #5

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

Similar topics

9
by: w3r3w0lf | last post by:
hello! I have a following situation: I have a byte array where at a certain location are stored 4 bytes, and these should be "put" into long variable (or any other 4 byte one). ie: byte...
8
by: Ramiro Barbosa, Jr. | last post by:
All, Any ideas on how to convert the first 8 bytes of raw uninterpreted sequence of bytes from 'char array;' (populated with _binary_ data read from a socket), into a 'long id'? Thank you! ...
44
by: RB | last post by:
How to extract bytes from long, starting from the last byte? For example, I have a long number: 0x12345678 I need to represent it as the following bytes list: 0x78, 0x56, 0x34, 0x12 Thanks in...
4
by: Lingyun Yang | last post by:
*** post for FREE via your newsreader at post.newsfeed.com *** Dear all, I have a file it's binary data viewed in UltraEdit is EF BB BF 0D 0A 3C ....... I want to read them into a int or long...
3
by: Dennis | last post by:
If I have a byte how would I port code from C++ to manipulate the byte array as if it were a long? For example: // C++ // assume the following // unsigned char* m_pPalette; // unsigned...
9
by: rsine | last post by:
I have developed a program that sends a command through the serial port to our business system and then reads from the buffer looking for a number. Everything worked great on my WinXP system, but...
11
by: bogusexception | last post by:
(or.. "I'm getting too much Tails and not enough Heads") I'm running into a very strange problem with random numbers and long numbers. To demonstrate the problem, I've created a simple test....
35
by: fermineutron | last post by:
For a while now i have been "playing" with a little C program to compute the factorial of large numbers. Currently it takes aboy 1 second per 1000 multiplications, that is 25000P1000 will take...
14
by: moumita | last post by:
Hi All, I need to convert 4 bytes to an unsigned long. Suppose I have one array like unsigned char buf.I need to convert these 4 bytes into a single unsigned long. Is the following piece of code...
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
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
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...

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.