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.




4292 posts

Uber Geek
+1 received by user: 628

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

OpenHAB: Gigabyte AMD A8 BrixOpenHAB with Aeotech ZWave Controller, Raspberry PI, Wemos D1 Mini, Zwave, Xiaomi Humidity and Temperature sensors and Bluetooth LE Sensors
Media:Chromecast v2, ATV4, Roku3, HDHomeRun Dual
Windows 10
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

497 posts

Ultimate Geek
+1 received by user: 64


  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.




4292 posts

Uber Geek
+1 received by user: 628

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

OpenHAB: Gigabyte AMD A8 BrixOpenHAB with Aeotech ZWave Controller, Raspberry PI, Wemos D1 Mini, Zwave, Xiaomi Humidity and Temperature sensors and Bluetooth LE Sensors
Media:Chromecast v2, ATV4, Roku3, HDHomeRun Dual
Windows 10
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


 
 
 
 




4292 posts

Uber Geek
+1 received by user: 628

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

OpenHAB: Gigabyte AMD A8 BrixOpenHAB with Aeotech ZWave Controller, Raspberry PI, Wemos D1 Mini, Zwave, Xiaomi Humidity and Temperature sensors and Bluetooth LE Sensors
Media:Chromecast v2, ATV4, Roku3, HDHomeRun Dual
Windows 10
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


Donate via Givealittle


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:





News »

Huawei unveils the P30 series
Posted 27-Mar-2019 05:13


Kordia announces recipient of inaugural Women in Technology Scholarship
Posted 26-Mar-2019 22:48


T&G Global and Abundant Robotics show first commercial robotic apple harvester
Posted 26-Mar-2019 21:34


Amazon introduces new Kindle with adjustable front light
Posted 21-Mar-2019 20:14


A call from the companies providing internet access for the great majority of New Zealanders, to the companies with the greatest influence over social media content
Posted 19-Mar-2019 15:21


Two e-scooter companies selected for Wellington trial
Posted 15-Mar-2019 17:33


GeForce GTX 1660 available now
Posted 15-Mar-2019 08:47


Artificial Intelligence to double the rate of innovation in New Zealand by 2021
Posted 13-Mar-2019 14:47


LG demonstrates smart home concepts at LG InnoFest
Posted 13-Mar-2019 14:45


New Zealanders buying more expensive smartphones
Posted 11-Mar-2019 09:52


2degrees Offers Amazon Prime Video to Broadband Customers
Posted 8-Mar-2019 14:10


D-Link ANZ launches D-Fend AC2600 Wi-Fi Router Protected by McAfee
Posted 7-Mar-2019 11:09


Slingshot commissions celebrities to design new modems
Posted 5-Mar-2019 08:58


Symantec Annual Threat Report reveals more ambitious, destructive and stealthy attacks
Posted 28-Feb-2019 10:14


FUJIFILM launches high performing X-T30
Posted 28-Feb-2019 09:40



Geekzone Live »

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


Support Geekzone »

Our community of supporters help make Geekzone possible. Click the button below to join them.

Support Geezone on PressPatron



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.