Geekzone: technology news, blogs, forums
Guest
Welcome Guest.
You haven't logged in yet. If you don't have an account you can register now.


davidcole

6099 posts

Uber Geek
+1 received by user: 1465

Trusted

#236434 1-Jun-2018 21:07
Send private message

So I have a string (in a config file), 1234.

 

I need to post that as two different hex values.  x12 and x34.

 

I honestly can't get how.  If I convert the string to hex, I get x0c and x22 - which is not what I want.  Now I could store as a string 18,52, but I want the number in the clear.

 

these two hex values will be going into an existing array, of which I'm currently hacking in in there by:

 

message += b'\x12'
message += b'\x34'





Previously known as psycik

Home Assistant: Gigabyte AMD A8 Brix, Home Assistant with Aeotech ZWave Controller, Raspberry PI, Wemos D1 Mini, Zwave, Shelly Humidity and Temperature sensors
Media:Chromecast v2, ATV4 4k, ATV4, HDHomeRun Dual
Server
Host Plex Server 3x3TB, 4x4TB using MergerFS, Samsung 850 evo 512 GB SSD, Proxmox Server with 1xW10, 2xUbuntu 22.04 LTS, Backblaze Backups, usenetprime.com fastmail.com Sharesies Trakt.TV Sharesight 


Create new topic

D.W

D.W
747 posts

Ultimate Geek
+1 received by user: 91


  #2027270 1-Jun-2018 21:37
Send private message

I might not be following what you're asking here, but using int(string, 16) will give you the value in hex.

 

e.g.

 

myVal = '12'

 

myNum = int(myVal, 16) will give you 18, which you can then convert back to hex as required.




davidcole

6099 posts

Uber Geek
+1 received by user: 1465

Trusted

  #2027291 1-Jun-2018 22:09
Send private message

D.W:

 

I might not be following what you're asking here, but using int(string, 16) will give you the value in hex.

 

e.g.

 

myVal = '12'

 

myNum = int(myVal, 16) will give you 18, which you can then convert back to hex as required.

 

 

Hmm doesn't seem to do what I want, but the value is correct:

 

myVal = '12'
myNum = int(myVal, 16)
message += hex(myNum)

 

When looking at the value

 

message = "\x00\x00\x00\x00\x16\x06\x10\x02')0x12"

 

so the 0x12 has just been added, but not sure how to add it as \x12 

 

the whole message should end 

 

"\x00\x00\x00\x00\x16\x06\x10\x02\x12\x34"

 

So half there.





Previously known as psycik

Home Assistant: Gigabyte AMD A8 Brix, Home Assistant with Aeotech ZWave Controller, Raspberry PI, Wemos D1 Mini, Zwave, Shelly Humidity and Temperature sensors
Media:Chromecast v2, ATV4 4k, ATV4, HDHomeRun Dual
Server
Host Plex Server 3x3TB, 4x4TB using MergerFS, Samsung 850 evo 512 GB SSD, Proxmox Server with 1xW10, 2xUbuntu 22.04 LTS, Backblaze Backups, usenetprime.com fastmail.com Sharesies Trakt.TV Sharesight 


davidcole

6099 posts

Uber Geek
+1 received by user: 1465

Trusted

  #2027295 1-Jun-2018 22:34
Send private message

I got it....had another google search and got the following:

 

where pcpassword is '1234'

 

hex_data = pcpassword.decode("hex")
message += hex_data

 

It gives me the data that I want - which incidentally logs on to my paradox alarm.





Previously known as psycik

Home Assistant: Gigabyte AMD A8 Brix, Home Assistant with Aeotech ZWave Controller, Raspberry PI, Wemos D1 Mini, Zwave, Shelly Humidity and Temperature sensors
Media:Chromecast v2, ATV4 4k, ATV4, HDHomeRun Dual
Server
Host Plex Server 3x3TB, 4x4TB using MergerFS, Samsung 850 evo 512 GB SSD, Proxmox Server with 1xW10, 2xUbuntu 22.04 LTS, Backblaze Backups, usenetprime.com fastmail.com Sharesies Trakt.TV Sharesight 


Create new topic








Geekzone Live »

Try automatic live updates from Geekzone directly in your browser, without refreshing the page, with Geekzone Live now.



Are you subscribed to our RSS feed? You can download the latest headlines and summaries from our stories directly to your computer or smartphone by using a feed reader.