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 Byte
Dim b As Byte
ba(0) = &h4
ba(1) = &h0
b = foo(ba)
</code>
What is foo() such that b contains &h40 ?
TIA
Charles
[I could write an algorithm for this, but there must surely be a succinct
conversion for it] 25 7231
* "Charles Law" <bl***@nowhere. com> scripsit: 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 Byte Dim b As Byte
ba(0) = &h4 ba(1) = &h0
b = foo(ba) </code>
What is foo() such that b contains &h40 ?
TIA
Charles [I could write an algorithm for this, but there must surely be a succinct conversion for it]
There can be many functions...
\\\
Public Function Foo(ByVal abyt() As Byte) As Byte
Return &H40
End Function
///
SCNR
--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Hi Herfried
As I was making coffee I realised my mistake (in the post). It should read
<code>
Dim ba(1) As Byte
Dim b As Byte
ba(0) = &h34
ba(1) = &h30
b = foo(ba)
</code>
Still looking for foo() such that b contains &h40.
Charles
"Herfried K. Wagner [MVP]" <hi************ ***@gmx.at> wrote in message
news:Oc******** *****@TK2MSFTNG P11.phx.gbl... * "Charles Law" <bl***@nowhere. com> scripsit: 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 Byte Dim b As Byte
ba(0) = &h4 ba(1) = &h0
b = foo(ba) </code>
What is foo() such that b contains &h40 ?
TIA
Charles [I could write an algorithm for this, but there must surely be a
succinct conversion for it]
There can be many functions...
\\\ Public Function Foo(ByVal abyt() As Byte) As Byte Return &H40 End Function ///
SCNR
-- Herfried K. Wagner [MVP] <URL:http://dotnet.mvps.org/>
Correction
Given the following
<code>
Dim ba(1) As Byte
Dim b As Byte
ba(0) = &h34
ba(1) = &h30
b = foo(ba)
</code>
What is foo() such that b contains &h40 ?
TIA
Charles
"Charles Law" <bl***@nowhere. com> wrote in message
news:uy******** ******@TK2MSFTN GP09.phx.gbl... 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 Byte Dim b As Byte
ba(0) = &h4 ba(1) = &h0
b = foo(ba) </code>
What is foo() such that b contains &h40 ?
TIA
Charles [I could write an algorithm for this, but there must surely be a succinct conversion for it]
"Charles Law" <bl***@nowhere. com> schrieb 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 Byte Dim b As Byte
ba(0) = &h4 ba(1) = &h0
b = foo(ba) </code>
What is foo() such that b contains &h40 ?
TIA
Charles [I could write an algorithm for this, but there must surely be a succinct conversion for it]
What if ba(0) or ba(1) > &Hf?
If both are [0; &HF]:
b = ba(0) << 4 or ba(1)
--
Armin
How to quote and why: http://www.plig.net/nnq/nquote.html http://www.netmeister.org/news/learn2quote.html
Hi Armin
Sorry for the confusion, but I think my correction is a bit slow coming
through. I should have written
ba(0) = &h34
ba(1) = &h30
Charles
"Armin Zingler" <az*******@free net.de> wrote in message
news:40******** *************** @news.freenet.d e... "Charles Law" <bl***@nowhere. com> schrieb 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 Byte Dim b As Byte
ba(0) = &h4 ba(1) = &h0
b = foo(ba) </code>
What is foo() such that b contains &h40 ?
TIA
Charles [I could write an algorithm for this, but there must surely be a succinct conversion for it]
What if ba(0) or ba(1) > &Hf?
If both are [0; &HF]:
b = ba(0) << 4 or ba(1)
-- Armin
How to quote and why: http://www.plig.net/nnq/nquote.html http://www.netmeister.org/news/learn2quote.html
* "Charles Law" <bl***@nowhere. com> scripsit: Given the following
<code> Dim ba(1) As Byte Dim b As Byte
ba(0) = &h34 ba(1) = &h30
b = foo(ba) </code>
What is foo() such that b contains &h40 ?
There are still thousands of ways to return this result. Do you have
other (input, outpuut) pairs?
--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
"Charles Law" <bl***@nowhere. com> schrieb Given the following
<code> Dim ba(1) As Byte Dim b As Byte
ba(0) = &h4 ba(1) = &h0
b = foo(ba) </code>
What is foo() such that b contains &h40 ?
What if ba(0) or ba(1) > &Hf?
If both are [0; &HF]:
b = ba(0) << 4 or ba(1)
Sorry for the confusion, but I think my correction is a bit slow coming through. I should have written
ba(0) = &h34 ba(1) = &h30
Expected result? &H3430?
Dim ba(1) As Byte
Dim s As Short
ba(0) = &H34
ba(1) = &H30
s = CShort(ba(0)) << 8 Or ba(1)
If you can exchange the byte order, this is also possible:
s = System.BitConve rter.ToInt16(ba , 0)
--
Armin
How to quote and why: http://www.plig.net/nnq/nquote.html http://www.netmeister.org/news/learn2quote.html
Thousands? I only need one ;-)
This is currently the only scenario. As a stop-gap, I have
<code>
Dim enc As New Text.ASCIIEncod ing
Return CByte("&H" & enc.GetString(b a))
</code>
which I imagine you will say is as good as any, but prepending "&H" to the
string just seems a bit 'kludgy'.
Charles
"Herfried K. Wagner [MVP]" <hi************ ***@gmx.at> wrote in message
news:u6******** ******@TK2MSFTN GP11.phx.gbl... * "Charles Law" <bl***@nowhere. com> scripsit: Given the following
<code> Dim ba(1) As Byte Dim b As Byte
ba(0) = &h34 ba(1) = &h30
b = foo(ba) </code>
What is foo() such that b contains &h40 ?
There are still thousands of ways to return this result. Do you have other (input, outpuut) pairs?
-- Herfried K. Wagner [MVP] <URL:http://dotnet.mvps.org/>
Hi Armin
No. Expected result still &H40.
Unfortunately, I cannot easily change the byte order as these are sent to me
from an external source, as binary coded hex digits.
Charles
"Armin Zingler" <az*******@free net.de> wrote in message
news:40******** *************** @news.freenet.d e... "Charles Law" <bl***@nowhere. com> schrieb > Given the following > > <code> > Dim ba(1) As Byte > Dim b As Byte > > ba(0) = &h4 > ba(1) = &h0 > > b = foo(ba) > </code> > > What is foo() such that b contains &h40 ?
What if ba(0) or ba(1) > &Hf?
If both are [0; &HF]:
b = ba(0) << 4 or ba(1)
Sorry for the confusion, but I think my correction is a bit slow coming through. I should have written
ba(0) = &h34 ba(1) = &h30
Expected result? &H3430?
Dim ba(1) As Byte Dim s As Short
ba(0) = &H34 ba(1) = &H30
s = CShort(ba(0)) << 8 Or ba(1)
If you can exchange the byte order, this is also possible:
s = System.BitConve rter.ToInt16(ba , 0) -- Armin
How to quote and why: http://www.plig.net/nnq/nquote.html http://www.netmeister.org/news/learn2quote.html This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Jim H |
last post by:
I am getting binary data form a database binary(8). I am copying it to a
byte array byte. I need to covert this to a number, ulong, so I can
write it to a string in hex format.
Any idea on how I do this? I don't see any conversion methods.
jim
|
by: War Eagle |
last post by:
I have int SomeNumber (which is less than 256) which I want to convert to 1 byte array so I might send it over TCP. Can someone help me out with writing this line of code?
TIA,
War Eagle
|
by: Angel Filev |
last post by:
Hi everyone,
I am trying to store a file as a binary array in an "image" field in SQL
Server 2000 database.
It works OK except for the ".PDF" files, which I believe get corrupted in
the
process of reading a stream to a byte array.
Uploading and downloading seems to work fine, but "Acrobat" pop ups
"The file is damaged and could not be...
|
by: Peted |
last post by:
In the default state
ie
somemethod(Byte array);
is the byte array passed by method or by reference ? or do you have to
use the ref keyword to be able to mod the contents of the orig array
from inside the method ?
|
by: Chunekit Pong |
last post by:
I have a BYTE array -
BYTE const* pbBinary
I would like to know how many bytes in that byte array
but if I do - sizeof(* pbBinary); - then I got 1
but if I do - sizeof( pbBinary); - then I got 4
I am sure the array has hundreds of bytes
| |
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 byte array (byte).
Can anyone tell me how to convert byte array to byte pointer in CSharp?
Please show me an simple example about how to do it....
|
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. ...
|
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...
|
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...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
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...
| |
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...
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |