473,761 Members | 7,290 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Convert Hex to Decimal in arraylist

Public ArrList As New ArrayList
Public bitvalue As Byte()

Public Sub addvalues()
Dim index As Integer
ArrList.Add(100 )
ArrList.Add(200 )
ArrList.Add(300 )
ArrList.Add(400 )
ArrList.Add(500 )
For Each value As Integer In ArrList
bitvalue = BitConverter.Ge tBytes(value)

'I need to convert the Hex value back to its corresponding decimal
value and place it into the bitvalue (0) and bitvalue (1)

senddata(bitval ue(0), bitvalue(1))
Next
End Sub

Sep 26 '07 #1
10 4968
On Sep 26, 4:03 pm, cmdolcet69 <colin_dolce... @hotmail.comwro te:
Public ArrList As New ArrayList
Public bitvalue As Byte()

Public Sub addvalues()
Dim index As Integer
ArrList.Add(100 )
ArrList.Add(200 )
ArrList.Add(300 )
ArrList.Add(400 )
ArrList.Add(500 )
For Each value As Integer In ArrList
bitvalue = BitConverter.Ge tBytes(value)

'I need to convert the Hex value back to its corresponding decimal
value and place it into the bitvalue (0) and bitvalue (1)

senddata(bitval ue(0), bitvalue(1))
Next
End Sub
Forget that popst...i was thinking of somthing else....sorry

Sep 26 '07 #2
"cmdolcet69 " <co************ @hotmail.comsch rieb
Public ArrList As New ArrayList
Public bitvalue As Byte()

Public Sub addvalues()
Dim index As Integer
ArrList.Add(100 )
ArrList.Add(200 )
ArrList.Add(300 )
ArrList.Add(400 )
ArrList.Add(500 )
For Each value As Integer In ArrList
bitvalue = BitConverter.Ge tBytes(value)

'I need to convert the Hex value back to its corresponding decimal
value and place it into the bitvalue (0) and bitvalue (1)

senddata(bitval ue(0), bitvalue(1))
Next
End Sub

Before I just saw your own answer to you own question, I was thinking you
are trying to fool us by asking this question. Sorry. :) Though, as I don't
want to discard the answer that I wrote meanwhile, here it is: ;-)
I don't see a hex value in the code. Hex values are strings. You do not have
a string in the code. Therefore, there can not be a hex value, and there is
nothing to convert.

Ok, let's start from the beginning:

In electronic data processing, in the digital world, information is stored
and transmitted using bits as the smallest unit of information. A bit can be
0 or 1, on or off, true or false. These are different, human readable words
for the two states a bit can be.

If you put 8 bits together, you get a byte. A byte can have 256 different
bit combinations. What kind of information is stored in a byte is a matter
of interpretation. For example, you can use 7 bits to store a numeric value
and 1 bit as the sign of the value, so you can store the values -128 to 127.
Without a sign, the values are 0 to 255.

The value stored in a byte can also be the code of a character. Due to
standardization , we are able to correctly interpret which character code
corresponds to which char. For example, the value 65 is the capital letter
"A". There are different character code standards. The table that describes
the relation between character code and character is called a code page. So,
one character can have different character codes in different code pages. In
the .Net Framework (and in VB.Net), two bytes are used to store a character.
The used code page is Unicode. This is necessary to support all the
characters used worldwide because two bytes can have 65,536 different
values.

When we talk about binary, octal, decimal and hexadecimal, we refer to the
human readable representation of a value that is stored in one or several
bits or bytes.

For example, let's take the binary value 1111011.

binary: 01111011
octal: 173
decimal: 123
hex: 7B

This is always the same value. As you can read this on your screen, you are
reading text. Texts are strings. This means, the value has been converted to
four different human readable strings using four different numeric bases (2,
8, 10 and 16).
Armin

Sep 26 '07 #3
Armin,

Nice written for the future, however in my idea you forgot to write how you
can represent a value in human readable Hex notation on a screen or
whatever. Something I always have to search for, but I am sure of something
you know direct from your head.

:-)

Cor

"Armin Zingler" <az*******@free net.deschreef in bericht
news:O2******** ******@TK2MSFTN GP06.phx.gbl...
"cmdolcet69 " <co************ @hotmail.comsch rieb
>Public ArrList As New ArrayList
Public bitvalue As Byte()

Public Sub addvalues()
Dim index As Integer
ArrList.Add(100 )
ArrList.Add(200 )
ArrList.Add(300 )
ArrList.Add(400 )
ArrList.Add(500 )
For Each value As Integer In ArrList
bitvalue = BitConverter.Ge tBytes(value)

'I need to convert the Hex value back to its corresponding decimal
value and place it into the bitvalue (0) and bitvalue (1)

senddata(bitva lue(0), bitvalue(1))
Next
End Sub


Before I just saw your own answer to you own question, I was thinking you
are trying to fool us by asking this question. Sorry. :) Though, as I
don't
want to discard the answer that I wrote meanwhile, here it is: ;-)
I don't see a hex value in the code. Hex values are strings. You do not
have
a string in the code. Therefore, there can not be a hex value, and there
is
nothing to convert.

Ok, let's start from the beginning:

In electronic data processing, in the digital world, information is stored
and transmitted using bits as the smallest unit of information. A bit can
be
0 or 1, on or off, true or false. These are different, human readable
words
for the two states a bit can be.

If you put 8 bits together, you get a byte. A byte can have 256 different
bit combinations. What kind of information is stored in a byte is a matter
of interpretation. For example, you can use 7 bits to store a numeric
value
and 1 bit as the sign of the value, so you can store the values -128 to
127.
Without a sign, the values are 0 to 255.

The value stored in a byte can also be the code of a character. Due to
standardization , we are able to correctly interpret which character code
corresponds to which char. For example, the value 65 is the capital letter
"A". There are different character code standards. The table that
describes
the relation between character code and character is called a code page.
So,
one character can have different character codes in different code pages.
In
the .Net Framework (and in VB.Net), two bytes are used to store a
character.
The used code page is Unicode. This is necessary to support all the
characters used worldwide because two bytes can have 65,536 different
values.

When we talk about binary, octal, decimal and hexadecimal, we refer to the
human readable representation of a value that is stored in one or several
bits or bytes.

For example, let's take the binary value 1111011.

binary: 01111011
octal: 173
decimal: 123
hex: 7B

This is always the same value. As you can read this on your screen, you
are
reading text. Texts are strings. This means, the value has been converted
to
four different human readable strings using four different numeric bases
(2,
8, 10 and 16).
Armin
Sep 27 '07 #4
"Cor Ligthert[MVP]" <no************ @planet.nlschri eb
Armin,

Nice written for the future, however in my idea you forgot to write
how you can represent a value in human readable Hex notation on a
screen or whatever. Something I always have to search for, but I am
sure of something you know direct from your head.

:-)
:-)

I already did it as a reply to him! That's why I didn't repeat it. Ok, let's
do so:

"- An Integer (System.Int32) is made of 4 Bytes.

- You get the single bytes into an array by using BitConverter.Ge tBytes

- Bytes are stored as binary digits. They don't have a Decimal nor a
Hexadecimal format.

- You can convert an Integer value into a string in different formats,
usually Decimal or Hexadecimal. Use the ToString function to do this. The
default is Decimal, otherwise use "X8" as the format string.

- You can convert a string, containing a number in hex format, into an
Integer value by using "Convert.ToInt3 2(TheString, 16)"

;-)
Armin

Sep 27 '07 #5
Armin,

Thanks,

:-)

Cor
Sep 27 '07 #6
On Sep 27, 6:21 am, "Armin Zingler" <az.nos...@free net.dewrote:
"Cor Ligthert[MVP]" <notmyfirstn... @planet.nlschri eb
Armin,
Nice written for the future, however in my idea you forgot to write
how you can represent a value in human readable Hex notation on a
screen or whatever. Something I always have to search for, but I am
sure of something you know direct from your head.
:-)

:-)

I already did it as a reply to him! That's why I didn't repeat it. Ok, let's
do so:

"- AnInteger(Syste m.Int32) is made of 4 Bytes.

- You get the single bytes into an array by using BitConverter.Ge tBytes

- Bytes are stored as binary digits. They don't have a Decimal nor a
Hexadecimal format.

- You can convert anIntegervalue into a string in different formats,
usually Decimal or Hexadecimal. Use the ToString function to do this. The
default is Decimal, otherwise use "X8" as the format string.

- You can convert a string, containing a number in hex format, into anIntegervalue by using "Convert.ToInt3 2(TheString, 16)"

;-)

Armin
Armin, reading your last post in this thread im trying to figure out
what i need to do here:
example i have put a message box to see what i should be getting back
from my variable.

what i get back is a value in byte of 15 and in another messagebox a
value of byte 38
now rading your above statment of an integer equals 4 bytes, how can
i get these value of 38 and 15 into an integer?
When i check these value i was getting an integer value of 3878 which
converting into HEX i get F26 and then i take the Hi_byte and Lo_byte
of the value i get the 38 and 15.....Now i get confused but how can i
convert this value back into an integer of 3878???

Oct 8 '07 #7
"cmdolcet69 " <co************ @hotmail.comsch rieb
On Sep 27, 6:21 am, "Armin Zingler" <az.nos...@free net.dewrote:
"Cor Ligthert[MVP]" <notmyfirstn... @planet.nlschri eb
Armin,
Nice written for the future, however in my idea you forgot to
write
how you can represent a value in human readable Hex notation on
a
screen or whatever. Something I always have to search for, but I
am
sure of something you know direct from your head.
:-)
:-)

I already did it as a reply to him! That's why I didn't repeat it.
Ok, let's
do so:

"- AnInteger(Syste m.Int32) is made of 4 Bytes.

- You get the single bytes into an array by using
BitConverter.Ge tBytes

- Bytes are stored as binary digits. They don't have a Decimal nor
a
Hexadecimal format.

- You can convert anIntegervalue into a string in different
formats,
usually Decimal or Hexadecimal. Use the ToString function to do
this. The
default is Decimal, otherwise use "X8" as the format string.

- You can convert a string, containing a number in hex format,
into anIntegervalue by using "Convert.ToInt3 2(TheString, 16)"

;-)

Armin

Armin, reading your last post in this thread im trying to figure out
what i need to do here:
example i have put a message box to see what i should be getting
back
from my variable.

what i get back is a value in byte of 15 and in another messagebox a
value of byte 38
now rading your above statment of an integer equals 4 bytes, how
can
i get these value of 38 and 15 into an integer?
When i check these value i was getting an integer value of 3878
which
converting into HEX i get F26 and then i take the Hi_byte and
Lo_byte
of the value i get the 38 and 15.....
Now i get confused but how can
i
convert this value back into an integer of 3878???

Dim b(3) As Byte
Dim i As Integer

b(0) = 38
b(1) = 15
b(2) = 0
b(3) = 0

i = BitConverter.To Int32(b, 0)

MsgBox("Decimal representation of variable i: " & i.ToString)
MsgBox("Hexadec imal representation of variable i: " & i.ToString("X") )

Armin

Oct 8 '07 #8
On Oct 8, 9:29 am, "Armin Zingler" <az.nos...@free net.dewrote:
"cmdolcet69 " <colin_dolce... @hotmail.comsch rieb


On Sep 27, 6:21 am, "Armin Zingler" <az.nos...@free net.dewrote:
"Cor Ligthert[MVP]" <notmyfirstn... @planet.nlschri eb
Armin,
Nice written for the future, however in my idea you forgot to
write
how you can represent a value in human readable Hex notation on
a
screen or whatever. Something I always have to search for, but I
am
sure of something you know direct from your head.
:-)
:-)
I already did it as a reply to him! That's why I didn't repeat it.
Ok, let's
do so:
"- AnInteger(Syste m.Int32) is made of 4 Bytes.
- You get the single bytes into an array by using
BitConverter.Ge tBytes
- Bytes are stored as binary digits. They don't have a Decimal nor
a
Hexadecimal format.
- You canconvertanInt egervalue into a string in different
formats,
usually Decimal or Hexadecimal. Use the ToString function to do
this. The
default is Decimal, otherwise use "X8" as the format string.
- You canconverta string, containing a number in hex format,
into anIntegervalue by using "Convert.ToInt3 2(TheString, 16)"
;-)
Armin
Armin, reading your last post in this thread im trying to figure out
what i need to do here:
example i have put a message box to see what i should be getting
back
from my variable.
what i get back is a value inbyteof 15 and in another messagebox a
value ofbyte38
now rading your above statment of an integer equals 4 bytes, how
can
i get these value of 38 and 15 into an integer?
When i check these value i was getting an integer value of 3878
which
converting into HEX i get F26 and then i take the Hi_byte and
Lo_byte
of the value i get the 38 and 15.....
Now i get confused but how can
i
convertthis value back into an integer of 3878???

Dim b(3) AsByte
Dim i As Integer

b(0) = 38
b(1) = 15
b(2) = 0
b(3) = 0

i = BitConverter.To Int32(b, 0)

MsgBox("Decimal representation of variable i: " & i.ToString)
MsgBox("Hexadec imal representation of variable i: " & i.ToString("X") )

Armin- Hide quoted text -

- Show quoted text -
Armin the wierd thing here is when i put a watch on my i it says its
9999, then when i get to the message box it will dsiplay a 9999
the reason the b(0) and b(1) is different is because those aren;t
constant number like above they are value of type byte in another
array, plus i mabtRxBuff (3)=38 and the mabtRxBuff(4) =15. Why does it
return a value of 9999?

Dim b(3) As Byte
Dim i As Integer
b(0) = mabtRxBuf(4)
b(1) = mabtRxBuf(3)
b(2) = 0
b(3) = 0
i = BitConverter.To Int32(b, 0)

Oct 8 '07 #9
"cmdolcet69 " <co************ @hotmail.comsch rieb

Dim b(3) AsByte
Dim i As Integer

b(0) = 38
b(1) = 15
b(2) = 0
b(3) = 0

i = BitConverter.To Int32(b, 0)

MsgBox("Decimal representation of variable i: " & i.ToString)
MsgBox("Hexadec imal representation of variable i: " &
i.ToString("X") )

Armin- Hide quoted text -

- Show quoted text -

Armin the wierd thing here is when i put a watch on my i it says its
9999, then when i get to the message box it will dsiplay a 9999
the reason the b(0) and b(1) is different is because those aren;t
constant number like above they are value of type byte in another
array, plus i mabtRxBuff (3)=38 and the mabtRxBuff(4) =15. Why does
it return a value of 9999?

Dim b(3) As Byte
Dim i As Integer
b(0) = mabtRxBuf(4)
b(1) = mabtRxBuf(3)
b(2) = 0
b(3) = 0
i = BitConverter.To Int32(b, 0)
You exchange 38 and 15. In my example, b(0) is 38 and b(1) is 15. In yours,
b(0) is 15 and b(1) is 39 (39!). It must be 39 because 39 * 256 + 15 = 9999.
Armin

Oct 8 '07 #10

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

Similar topics

4
3899
by: Julian Hernandez Gomez | last post by:
Hi ! This is maybe a silly question, but... is there a "easy way" to make eval() convert all floating numbers to Decimal objects and return a Decimal? for example: eval('1.00000001+0.1111111') --> convert each number to a Decimal object,
4
9269
by: Rodusa | last post by:
I am having problem to apply updates into this function below. I tried using cursor for updates, etc. but no success. Sql server keeps telling me that I cannot execute insert or update from inside a function and it gives me an option that I could write an extended stored procedure, but I don't have a clue of how to do it. To quickly fix the problem the only solution left in my case is to convert this recursive function into one recursive...
4
9768
by: aevans1108 | last post by:
expanding this message to microsoft.public.dotnet.xml Greetings Please direct me to the right group if this is an inappropriate place to post this question. Thanks. I want to format a numeric value according to an arbitrary regular expression.
7
7121
by: whatluo | last post by:
Hi, all I'm now working on a program which will convert dec number to hex and oct and bin respectively, I've checked the clc but with no luck, so can anybody give me a hit how to make this done without strtol or s/printf function. Thanks, whatluo.
3
12922
by: JenHu | last post by:
Hi all, I have to read from a text file and generate values and insert to database. But first of all, when the text file contains '0000000000', I received a sEfundAmt value = 0D instead of 0.0 on sEfundAmt = Decimal.Parse(Mid$(sRetLine, 30, 10)) / 100.0 For example, in the text file, value is '0000150776', I want to
3
7715
by: PeterK | last post by:
I am trying to set Public overridable CreditlimitS() as System.Data.SqlTypes.SqlMoney to Creditlimit as Double like CreditLimitS=creditlimit and get this error "Value of type double cannot be converted to System.Data.SqlTypes.SqlMoney " How do I get creditlimit into creditlimitS? There seems to be no conversion function. TIA
3
7163
by: mlafarlett | last post by:
In the example below, the 'convert.ToDecimal' removes the trailing 5. I'd like to get the number, in tact, moved to the decimal variable. Any help would be greatly appreciated. Dim dcml As Decimal Dim dbl As Double = 544.4000244140625 dcml = Convert.ToDecimal(dbl) Debug.WriteLine(dcml.ToString)
2
15214
karthickbabu
by: karthickbabu | last post by:
Hi In my application i want to convert integer to decimal. I get a input and using convert function to convert into decimal. But it shows as it self. My code like as below, Is any wrong in my code dim input as long // I declare as long dim decimaloutput as decimal decimaloutput = Convert.ToDecimal(input) label1.text = decimaloutput.ToString()
1
2965
by: Vitaliy | last post by:
Hi I got this wired exception periodically (Python 2.5, Django based application) what does it mean ?
0
9531
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
9957
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9775
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...
0
8780
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7332
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
5229
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...
0
5373
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3881
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
3
3456
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.