Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / VB.NET / October 2007

Tip: Looking for answers? Try searching our database.

Convert Hex to Decimal in arraylist

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
cmdolcet69 - 26 Sep 2007 21:03 GMT
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.GetBytes(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(bitvalue(0), bitvalue(1))
       Next
   End Sub
cmdolcet69 - 26 Sep 2007 21:28 GMT
> Public ArrList As New ArrayList
>     Public bitvalue As Byte()
[quoted text clipped - 15 lines]
>         Next
>     End Sub

Forget that popst...i was thinking of somthing else....sorry
Armin Zingler - 26 Sep 2007 22:13 GMT
> Public ArrList As New ArrayList
>    Public bitvalue As Byte()
[quoted text clipped - 15 lines]
>        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
Cor Ligthert[MVP] - 27 Sep 2007 04:33 GMT
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

>> Public ArrList As New ArrayList
>>    Public bitvalue As Byte()
[quoted text clipped - 79 lines]
>
> Armin
Armin Zingler - 27 Sep 2007 11:21 GMT
> Armin,
>
[quoted text clipped - 4 lines]
>
> :-)

:-)

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.GetBytes

- 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.ToInt32(TheString, 16)"

;-)

Armin
Cor Ligthert [MVP] - 27 Sep 2007 12:05 GMT
Armin,

Thanks,

:-)

Cor
cmdolcet69 - 08 Oct 2007 14:01 GMT
> > Armin,
>
[quoted text clipped - 26 lines]
>
> 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???
Armin Zingler - 08 Oct 2007 14:29 GMT
> On Sep 27, 6:21 am, "Armin Zingler" <az.nos...@freenet.de> wrote:
> >
[quoted text clipped - 57 lines]
> 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.ToInt32(b, 0)

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

Armin
cmdolcet69 - 08 Oct 2007 18:18 GMT
> > > > Armin,
>
[quoted text clipped - 72 lines]
>
> - 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.ToInt32(b, 0)
Armin Zingler - 08 Oct 2007 19:09 GMT
> >     Dim b(3) AsByte
> >     Dim i As Integer
[quoted text clipped - 28 lines]
>                    b(3) = 0
>                    i = BitConverter.ToInt32(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
cmdolcet69 - 08 Oct 2007 19:55 GMT
> > >     Dim b(3) AsByte
> > >     Dim i As Integer
[quoted text clipped - 35 lines]
>
> - Show quoted text -

Thank you

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.