msvisual.com Forum Index
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

"space" in hex?

 
Post new topic   Reply to topic    msvisual.com Forum Index -> VB Syntax
Author Message
dalz via VBMonster.com



Joined: 04 Oct 2007
Posts: 7

PostPosted: Wed Jun 27, 2007 11:22 am    Post subject: "space" in hex? Reply with quote

I have problem in converting "space" to hex and be read again as "space" in
string

Ex: input text = abcd defg
I must convert this text to hex so it can be store to the card
Then when the card is read by the reader it must return the same result =
abcd defg

But what happening is:

input text = abcd defg
result in hex = 61 62 63 64 20 64 65 66 67
convert it again to string = abcdAIKM'

how to read the "space"??

thanks

--
Message posted via http://www.vbmonster.com

Archived from group: microsoft>public>vb>syntax
Back to top
View user's profile Send private message
Argusy



Joined: 04 Oct 2007
Posts: 105

PostPosted: Wed Jun 27, 2007 9:41 pm    Post subject: Re: "space" in hex? Reply with quote

dalz via VBMonster.com wrote:
> I have problem in converting "space" to hex and be read again as "space" in
> string
>
> Ex: input text = abcd defg
> I must convert this text to hex so it can be store to the card
> Then when the card is read by the reader it must return the same result =
> abcd defg
>
> But what happening is:
>
> input text = abcd defg
> result in hex = 61 62 63 64 20 64 65 66 67
> convert it again to string = abcdAIKM'
>
> how to read the "space"??
>
> thanks
>

Something wrong, there.

Lower case "abcd defg" should be 96, 97, 98, 99 20 99 100 101 102

Take another look at your encrypting algorithm. It aint right

Argusy
Back to top
View user's profile Send private message
Argusy



Joined: 04 Oct 2007
Posts: 105

PostPosted: Wed Jun 27, 2007 10:23 pm    Post subject: Re: "space" in hex? Reply with quote

Argusy wrote:
> dalz via VBMonster.com wrote:
>
>> I have problem in converting "space" to hex and be read again as
>> "space" in
>> string
>>
>> Ex: input text = abcd defg
>> I must convert this text to hex so it can be store to the card
>> Then when the card is read by the reader it must return the same result =
>> abcd defg
>>
>> But what happening is:
>>
>> input text = abcd defg
>> result in hex = 61 62 63 64 20 64 65 66 67 convert it again to string
>> = abcdAIKM'
>>
>> how to read the "space"??
>>
>> thanks
>>
>
> Something wrong, there.
>
> Lower case "abcd defg" should be 96, 97, 98, 99 20 99 100 101 102
>
> Take another look at your encrypting algorithm. It aint right
>
> Argusy
>

Innit marvelous!!

Go away for 30 minutes, re-read it and you can see I've been a right proper nong.
The hex (Hex, Graham, HEX) conversion is correct as dalz has wrote (sic) it.

Please show the code you're using - then we can figure out what the problem is

Argusy
Back to top
View user's profile Send private message
Larry Serflaten



Joined: 04 Oct 2007
Posts: 2644

PostPosted: Wed Jun 27, 2007 11:15 am    Post subject: Re: "space" in hex? Reply with quote

"dalz via VBMonster.com" wrote

> I must convert this text to hex so it can be store to the card
> Then when the card is read by the reader it must return the same result =
> abcd defg

Try to remember that it matters little how you display the data, the
bottom line is that you are always working with numbers. Whether
you want them displayed as characters, hexidecimal, or decimal values,
they are just numbers.


> But what happening is:
>
> input text = abcd defg
> result in hex = 61 62 63 64 20 64 65 66 67
> convert it again to string = abcdAIKM'
>
> how to read the "space"??

Without knowing what code you are using, the mistake can't be known,
but I'd wager the problem is with your conversion code from hex to
characters. It is fairly simple to display all three:

Dim b() As Byte
Dim i As Long

b = "abcd efgh"
For i = 0 To 17
Debug.Print i, b(i), Hex(b(i)), Chr(b(i))
Next
Debug.Print b

What does your conversion code look like?

LFS
Back to top
View user's profile Send private message
dalz via VBMonster.com



Joined: 04 Oct 2007
Posts: 7

PostPosted: Thu Jun 28, 2007 6:13 am    Post subject: Re: "space" in hex? Reply with quote

I'm using this code below (before that, I've already converted the hex to
binary)

the result in binary for "abcd efgh":
1100001 1100010 1100011 1100100 100000 1100101 1100110 1100111 1101000


Note: This code below is not my own code but I got it from googling^^
Argusy, 97 98 99 100 20 101... are the equivalent Decimal / Ascii
Value for "abcd d.." not Hex

Private Sub cmdBinaryToAscii_Click()
Dim bin As String
Dim result As String
Dim i As Integer
Dim next_char As String
Dim ascii As Long

bin = txtBinary.Text
result = ""
For i = 1 To Len(bin) + 18 Step 8
next_char = Mid$(bin, i, Cool
ascii = BinaryToLong(next_char)
result = result & Chr$(ascii)
Next i

txtAscii.Text = result
End Sub

Private Function BinaryToLong(ByVal binary_value As String) As Long
Dim hex_result As String
Dim nibble_num As Integer
Dim nibble_value As Integer
Dim factor As Integer
Dim bit As Integer

' Remove any leading &B if present.
' (Note: &B is not a standard prefix, it just
' makes some sense.)
binary_value = UCase$(Trim$(binary_value))
If Left$(binary_value, 2) = "&B" Then
binary_value = Mid$(binary_value, 3)
End If

' Strip out spaces in case the bytes are separated
' by spaces.
binary_value = Replace(binary_value, " ", "")

' Left pad with zeros so we have a full 32 bits.
binary_value = Right$(String(32, "0") & _
binary_value, 32)

' Read the bits in nibbles from right to left.
' (A nibble is half a byte. )
For nibble_num = 7 To 0 Step -1
' Convert this nibble into a hexadecimal string.
factor = 1
nibble_value = 0

' Read the nibble's bits from right to left.
For bit = 3 To 0 Step -1
If Mid$(binary_value, _
1 + nibble_num * 4 + bit, 1) = "1" _
Then
nibble_value = nibble_value + factor
End If
factor = factor * 2
Next bit

' Add the nibble's value to the left of the
' result hex string.
hex_result = Hex$(nibble_value) & hex_result
Next nibble_num

' Convert the result string into a long.
BinaryToLong = CLng("&H" & hex_result)
End Function

Thanks..


Larry Serflaten wrote:
>> I must convert this text to hex so it can be store to the card
>> Then when the card is read by the reader it must return the same result =
>> abcd defg
>
>Try to remember that it matters little how you display the data, the
>bottom line is that you are always working with numbers. Whether
>you want them displayed as characters, hexidecimal, or decimal values,
>they are just numbers.
>
>> But what happening is:
>>
>[quoted text clipped - 3 lines]
>>
>> how to read the "space"??
>
>Without knowing what code you are using, the mistake can't be known,
>but I'd wager the problem is with your conversion code from hex to
>characters. It is fairly simple to display all three:
>
>Dim b() As Byte
>Dim i As Long
>
> b = "abcd efgh"
> For i = 0 To 17
> Debug.Print i, b(i), Hex(b(i)), Chr(b(i))
> Next
> Debug.Print b
>
>What does your conversion code look like?
>
>LFS

--
Message posted via http://www.vbmonster.com
Back to top
View user's profile Send private message
Argusy



Joined: 04 Oct 2007
Posts: 105

PostPosted: Thu Jun 28, 2007 9:32 pm    Post subject: Re: "space" in hex? Reply with quote

dalz via VBMonster.com wrote:
> I'm using this code below (before that, I've already converted the hex to
> binary)
>
> the result in binary for "abcd efgh":
> 1100001 1100010 1100011 1100100 100000 1100101 1100110 1100111 1101000
>
>
> Note: This code below is not my own code but I got it from googling^^
> Argusy, 97 98 99 100 20 101... are the equivalent Decimal / Ascii
> Value for "abcd d.." not Hex



Yeah, I know - see my second reply about 42 minutes later (after a feed. Must
have improved my recognition of hex characters )

Graham
Back to top
View user's profile Send private message
dalz via VBMonster.com



Joined: 04 Oct 2007
Posts: 7

PostPosted: Thu Jun 28, 2007 12:58 pm    Post subject: Re: "space" in hex? Reply with quote

^-^ I have solved my problem

Turns out a space can't be converted to hex

But I've already find the solution..accidentally
I've just realized that the data in the card already read in ascii--' (by
using the ".dll")
so I don't have to convert it from hex anymore

thanks all


Argusy wrote:
>> I'm using this code below (before that, I've already converted the hex to
>> binary)
>[quoted text clipped - 5 lines]
>> Argusy, 97 98 99 100 20 101... are the equivalent Decimal / Ascii
>> Value for "abcd d.." not Hex
>
>
>
>Yeah, I know - see my second reply about 42 minutes later (after a feed. Must
>have improved my recognition of hex characters )
>
>Graham

--
Message posted via VBMonster.com
http://www.vbmonster.com/Uwe/Forums.aspx/vb-syntax/200706/1
Back to top
View user's profile Send private message
argusy



Joined: 04 Oct 2007
Posts: 1

PostPosted: Mon Jul 02, 2007 4:14 pm    Post subject: Re: "space" in hex? Reply with quote

Dalz - comments in line

dalz via VBMonster.com wrote in message@uwe...
> ^-^ I have solved my problem
>
> Turns out a space can't be converted to hex

Yes it can

> But I've already find the solution..accidentally
> I've just realized that the data in the card already read in ascii--' (by
> using the ".dll")
> so I don't have to convert it from hex anymore
>
> thanks all


this
"1100001 1100010 1100011 1100100 100000 1100101 1100110 1100111 1101000"
7 bits 7 7 7 6!! 7
7 7 7
is 4 groups of 7 bits, one of 6, followed by 4 of 7 again - stuffed up
your decoding
("abcd" space (6bits) then "defg")


There was a challenge to get your code working.
Some errors of logic in yours, so I re-thunked it

Graham

Private Sub cmdBinaryToAscii_Click()
Dim bin As String
Dim result As String
Dim i As Integer
Dim asciiArray

bin = txtBinary.Text
result = ""
asciiArray = Split(bin, " ") 'separate out the binary info

For i = 0 To UBound(asciiArray)
result = result & Chr$(BinaryToLong(asciiArray(i)))
Next i

txtASCII.Text = result 'I used another textbox
End Sub

Private Function BinaryToLong(ByVal binary_value As String) As Long
Dim i As Integer

binary_value = StrReverse(binary_value) 'set for a left to right scan
' could have left that for a right to left scan

' convert binary data to a long
For i = 0 To Len(binary_value)
If Mid$(binary_value, i + 1, 1) = "1" Then
BinaryToLong = BinaryToLong + 2 ^ i 'use power of 2
End If
Next i

End Function

Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    msvisual.com Forum Index -> VB Syntax All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group