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.


4087 posts

Uber Geek
+1 received by user: 542

Trusted

Topic # 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

NextPVR: 
Gigabyte AMD A8 Brix --> Samsung LA46A650D via HDMI, NextPVR,
OpenHAB: ODroid C2 eMMC DriveOpenHAB with Aeotech ZWave Controller, Raspberry PI, Wemos D1 Mini, Zwave and Bluetooth LE Sensors
Media:Chromecast v2, ATV4, Roku3, HDHomeRun Dual
Windows 2012 
Host (Plex Server/Crashplan): 2x2TB, 2x3TB, 1x4TB using DriveBender, Samsung 850 evo 512 GB SSD, Hyper-V Server with 1xW10, 1xW2k8, 2xUbuntu 16.04 LTS, Crashplan, NextPVR channel for Plex,NextPVR Metadata Agent and Scanner for Plex


Create new topic

D.W

457 posts

Ultimate Geek
+1 received by user: 54


  Reply # 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.




4087 posts

Uber Geek
+1 received by user: 542

Trusted

  Reply # 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

NextPVR: 
Gigabyte AMD A8 Brix --> Samsung LA46A650D via HDMI, NextPVR,
OpenHAB: ODroid C2 eMMC DriveOpenHAB with Aeotech ZWave Controller, Raspberry PI, Wemos D1 Mini, Zwave and Bluetooth LE Sensors
Media:Chromecast v2, ATV4, Roku3, HDHomeRun Dual
Windows 2012 
Host (Plex Server/Crashplan): 2x2TB, 2x3TB, 1x4TB using DriveBender, Samsung 850 evo 512 GB SSD, Hyper-V Server with 1xW10, 1xW2k8, 2xUbuntu 16.04 LTS, Crashplan, NextPVR channel for Plex,NextPVR Metadata Agent and Scanner for Plex




4087 posts

Uber Geek
+1 received by user: 542

Trusted

  Reply # 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

NextPVR: 
Gigabyte AMD A8 Brix --> Samsung LA46A650D via HDMI, NextPVR,
OpenHAB: ODroid C2 eMMC DriveOpenHAB with Aeotech ZWave Controller, Raspberry PI, Wemos D1 Mini, Zwave and Bluetooth LE Sensors
Media:Chromecast v2, ATV4, Roku3, HDHomeRun Dual
Windows 2012 
Host (Plex Server/Crashplan): 2x2TB, 2x3TB, 1x4TB using DriveBender, Samsung 850 evo 512 GB SSD, Hyper-V Server with 1xW10, 1xW2k8, 2xUbuntu 16.04 LTS, Crashplan, NextPVR channel for Plex,NextPVR Metadata Agent and Scanner for Plex


Create new topic

Twitter »

Follow us to receive Twitter updates when new discussions are posted in our forums:



Follow us to receive Twitter updates when news items and blogs are posted in our frontpage:



Follow us to receive Twitter updates when tech item prices are listed in our price comparison site:



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.

Alternatively, you can receive a daily email with Geekzone updates.