473,486 Members | 1,970 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

String to Hex

I have the string "15" which I need represented as a hex number - ie &H15

Simple I would have thought but I can't find the answer.

-Jerry
Sep 13 '07 #1
12 3287
On Sep 13, 10:04 am, "Jerry Spence1" <jerry.spe...@somewhere.co.uk>
wrote:
I have the string "15" which I need represented as a hex number - ie &H15

Simple I would have thought but I can't find the answer.

-Jerry
It would be:

Dim int As Integer = Integer.Parse("15",
Globalization.NumberStyles.HexNumber)

If I remember correctly

Thanks,

Seth Rowe

Sep 13 '07 #2

"rowe_newsgroups" <ro********@yahoo.comwrote in message
news:11**********************@r34g2000hsd.googlegr oups.com...
On Sep 13, 10:04 am, "Jerry Spence1" <jerry.spe...@somewhere.co.uk>
wrote:
>I have the string "15" which I need represented as a hex number - ie &H15

Simple I would have thought but I can't find the answer.

-Jerry

It would be:

Dim int As Integer = Integer.Parse("15",
Globalization.NumberStyles.HexNumber)

If I remember correctly

Thanks,

Seth Rowe
That converts the number to 21. I need to keep 15. I have tried starting
with a string of "&H15" and playing around with that but still can't seem to
do it.

-Jerry
Sep 13 '07 #3
On Sep 13, 10:21 am, "Jerry Spence1" <jerry.spe...@somewhere.co.uk>
wrote:
"rowe_newsgroups" <rowe_em...@yahoo.comwrote in message

news:11**********************@r34g2000hsd.googlegr oups.com...
On Sep 13, 10:04 am, "Jerry Spence1" <jerry.spe...@somewhere.co.uk>
wrote:
I have the string "15" which I need represented as a hex number - ie &H15
Simple I would have thought but I can't find the answer.
-Jerry
It would be:
Dim int As Integer = Integer.Parse("15",
Globalization.NumberStyles.HexNumber)
If I remember correctly
Thanks,
Seth Rowe

That converts the number to 21. I need to keep 15. I have tried starting
with a string of "&H15" and playing around with that but still can't seem to
do it.

-Jerry
Sorry, I apparently misunderstood what you are trying to do.

As a matter of fact - I still have no idea what you are trying to do.
Could you try explaining in more detail what exactly you are trying to
do and why?

Thanks,

Seth Rowe

Sep 13 '07 #4
That converts the number to 21. I need to keep 15. I have tried
starting with a string of "&H15" and playing around with that but
still can't seem to do it.

&H15 *is* 21 in decimal (and integers are stored in decimal)

If you're just after the string "&H15" from a string of "15" then just add
"&H" on the front..

I guess we're just not clear on what you want.

Perhaps it would help if you explain what you would like to do with what
you end up with?
--
Rory
Sep 13 '07 #5

"rowe_newsgroups" <ro********@yahoo.comwrote in message
news:11**********************@r29g2000hsg.googlegr oups.com...
On Sep 13, 10:21 am, "Jerry Spence1" <jerry.spe...@somewhere.co.uk>
wrote:
>"rowe_newsgroups" <rowe_em...@yahoo.comwrote in message

news:11**********************@r34g2000hsd.googleg roups.com...
On Sep 13, 10:04 am, "Jerry Spence1" <jerry.spe...@somewhere.co.uk>
wrote:
I have the string "15" which I need represented as a hex number - ie
&H15
>Simple I would have thought but I can't find the answer.
>-Jerry
It would be:
Dim int As Integer = Integer.Parse("15",
Globalization.NumberStyles.HexNumber)
If I remember correctly
Thanks,
Seth Rowe

That converts the number to 21. I need to keep 15. I have tried starting
with a string of "&H15" and playing around with that but still can't seem
to
do it.

-Jerry

Sorry, I apparently misunderstood what you are trying to do.

As a matter of fact - I still have no idea what you are trying to do.
Could you try explaining in more detail what exactly you are trying to
do and why?

Thanks,

Seth Rowe
Thanks Seth

I have "15" as a string. I need to do some XOR and ANDing of bits. I can't
directly do:

"15" AND 01

so I need to make 15 a hex value first (&H15). I feel I need something like
ctype(integer,hexvalue) if such a thing existed. I'm sure I will kick myself
when I find the answer.

-Jerry
Sep 13 '07 #6
On Sep 13, 10:36 am, "Jerry Spence1" <jerry.spe...@somewhere.co.uk>
wrote:
"rowe_newsgroups" <rowe_em...@yahoo.comwrote in message

news:11**********************@r29g2000hsg.googlegr oups.com...
On Sep 13, 10:21 am, "Jerry Spence1" <jerry.spe...@somewhere.co.uk>
wrote:
"rowe_newsgroups" <rowe_em...@yahoo.comwrote in message
>news:11**********************@r34g2000hsd.googleg roups.com...
On Sep 13, 10:04 am, "Jerry Spence1" <jerry.spe...@somewhere.co.uk>
wrote:
I have the string "15" which I need represented as a hex number - ie
&H15
Simple I would have thought but I can't find the answer.
-Jerry
It would be:
Dim int As Integer = Integer.Parse("15",
Globalization.NumberStyles.HexNumber)
If I remember correctly
Thanks,
Seth Rowe
That converts the number to 21. I need to keep 15. I have tried starting
with a string of "&H15" and playing around with that but still can't seem
to
do it.
-Jerry
Sorry, I apparently misunderstood what you are trying to do.
As a matter of fact - I still have no idea what you are trying to do.
Could you try explaining in more detail what exactly you are trying to
do and why?
Thanks,
Seth Rowe

Thanks Seth

I have "15" as a string. I need to do some XOR and ANDing of bits. I can't
directly do:

"15" AND 01

so I need to make 15 a hex value first (&H15). I feel I need something like
ctype(integer,hexvalue) if such a thing existed. I'm sure I will kick myself
when I find the answer.

-Jerry
Can't you just use the byte datatype instead of string?

Thanks,

Seth Rowe

Sep 13 '07 #7
I have "15" as a string. I need to do some XOR and ANDing of bits. I
can't directly do:

"15" AND 01

so I need to make 15 a hex value first (&H15). I feel I need
something like ctype(integer,hexvalue) if such a thing existed. I'm
sure I will kick myself when I find the answer.
Bitwise ANDing of 2 numbers should work regardless of whether they are decimal
or hex because internally the mahince only understands nbbinary anyway.
Thus
-------------------------------------
Dim Result as Integer = CInt("&H" & "15") AND CInt("01")
-------------------------------------

This is untested but should result in "Result" containing an integer in this
case 1 (Also 1 in HEX)

Does this help?

--
Rory
Sep 13 '07 #8
"Jerry Spence1" <je**********@somewhere.co.ukschrieb

Thanks Seth

I have "15" as a string. I need to do some XOR and ANDing of bits. I
can't directly do:

"15" AND 01

so I need to make 15 a hex value first (&H15). I feel I need
something like ctype(integer,hexvalue) if such a thing existed. I'm
sure I will kick myself when I find the answer.
Why is "15" there as a string not as a number? If that's not avoidable, use
Convert.ToInt32 to convert it to an integer first, then use numeric
operators.

dim number as integer

number = convert.toint32("15", 16) '16 is the base (hexadecimal)
number = number and 1


Armin

Sep 13 '07 #9

"Rory Becker" <Ro********@newsgroup.nospamwrote in message
news:b0**************************@msnews.microsoft .com...
>I have "15" as a string. I need to do some XOR and ANDing of bits. I
can't directly do:

"15" AND 01

so I need to make 15 a hex value first (&H15). I feel I need
something like ctype(integer,hexvalue) if such a thing existed. I'm
sure I will kick myself when I find the answer.

Bitwise ANDing of 2 numbers should work regardless of whether they are
decimal or hex because internally the mahince only understands nbbinary
anyway.
Thus -------------------------------------
Dim Result as Integer = CInt("&H" & "15") AND CInt("01")
-------------------------------------

This is untested but should result in "Result" containing an integer in
this case 1 (Also 1 in HEX)

Does this help?

--
Rory

Thanks Rory - yes it does help. I didn't realise that I could so bitwise
comparisons on a decimal number. It works OK.

Thanks a lot and thanks to Seth for your input as well.

-Jerry
Sep 13 '07 #10

"Armin Zingler" <az*******@freenet.dewrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
"Jerry Spence1" <je**********@somewhere.co.ukschrieb
>

Thanks Seth

I have "15" as a string. I need to do some XOR and ANDing of bits. I
can't directly do:

"15" AND 01

so I need to make 15 a hex value first (&H15). I feel I need
something like ctype(integer,hexvalue) if such a thing existed. I'm
sure I will kick myself when I find the answer.

Why is "15" there as a string not as a number? If that's not avoidable,
use Convert.ToInt32 to convert it to an integer first, then use numeric
operators.

dim number as integer

number = convert.toint32("15", 16) '16 is the base (hexadecimal)
number = number and 1


Armin
That's a neat trick. Thanks Armin

-Jerry
Sep 13 '07 #11
Hi Jerry,
To convert a string into HEX you need to it char by char ie: convert every
char into it's ascii value then convert the ascii to HEX:
here is the code:

Private Sub txtNormal_TextChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles txtNormal.TextChanged

Dim sTemp As String

Dim sTemp2 As StringBuilder = New StringBuilder

For i As Integer = 0 To Me.txtNormal.Text.Length - 1

sTemp = Me.txtNormal.Text.Substring(i, 1)

sTemp2.Append(Hex(Asc(sTemp)))

Next

Me.txtHEX.Text = sTemp2.ToString()

End Sub

hope this will help

cheers

"Jerry Spence1" <je**********@somewhere.co.ukwrote in message
news:13*************@corp.supernews.com...
>I have the string "15" which I need represented as a hex number - ie &H15

Simple I would have thought but I can't find the answer.

-Jerry


Sep 23 '07 #12
Jerry Spence1 wrote:
Thanks Rory - yes it does help. I didn't realise that I could so bitwise
comparisons on a decimal number. It works OK.
Actually it's not a decimal number at all, it's just an integer.

Decimal and hexadecimal are two ways of representing numbers as text. As
long as you handle the integer as an integer, it doesn't have any
textual representation at all, it's just some bits in memory.

Whenever you display the value of an integer, a string is created that
is the textual representation of the integer, as the integer itself
can't be displayed as text.

--
Göran Andersson
_____
http://www.guffa.com
Sep 23 '07 #13

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

Similar topics

16
6701
by: Krakatioison | last post by:
My sites navigation is like this: http://www.newsbackup.com/index.php?n=000000000040900000 , depending on the variable "n" (which is always a number), it will take me anywhere on the site......
5
31154
by: Stu Cazzo | last post by:
I have the following: String myStringArray; String myString = "98 99 100"; I want to split up myString and put it into myStringArray. If I use this: myStringArray = myString.split(" "); it...
9
7985
by: John F Dutcher | last post by:
I use code like the following to retrieve fields from a form: recd = recd.append(string.ljust(form.getfirst("lname",' '),15)) recd.append(string.ljust(form.getfirst("fname",' '),15)) etc.,...
10
8142
by: Angus Leeming | last post by:
Hello, Could someone explain to me why the Standard conveners chose to typedef std::string rather than derive it from std::basic_string<char, ...>? The result of course is that it is...
2
4754
by: Andrew | last post by:
I have written two classes : a String Class based on the book " C++ in 21 days " and a GenericIpClass listed below : file GenericStringClass.h // Generic String class
29
4273
by: zoro | last post by:
Hi, I am new to C#, coming from Delphi. In Delphi, I am using a 3rd party string handling library that includes some very useful string functions, in particular I'm interested in BEFORE (return...
2
3159
by: Badass Scotsman | last post by:
Hello, Using VB and ASP,NET I would like to be able to search a STRING for a smaller STRING within, based on the characters which appear before and after. For example: String1 = " That was...
15
50126
by: morleyc | last post by:
Hi, i would like to remove a number of characters from my string (\t \r \n which are throughout the string), i know regex can do this but i have no idea how. Any pointers much appreciated. Chris
11
3033
by: ramu | last post by:
Hi, Suppose I have a string like this: "I have a string \"and a inner string\\\" I want to remove space in this string but not in the inner string" In the above string I have to remove...
8
4721
by: drjay1627 | last post by:
hello, This is my 1st post here! *welcome drjay* Thanks! I look answering questions and getting answers to other! Now that we got that out of the way. I'm trying to read in a string and...
0
7099
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
6964
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
7123
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,...
1
6842
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...
1
4864
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
3070
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1378
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 ...
1
598
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
262
bsmnconsultancy
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...

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.