www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Convert hexadecimal to decimal

reply "confused" <lance.macdonald gmail.com> writes:
hi team!

I'm using this swift piece of code to seek out the Option 26 DHCP 
is deploying and output to the screen: 
https://github.com/CyberShadow/dhcptest/blob/master/dhcptest.d
(props for code CyberShadow).

When I get the value it says 0578. I've used an online converter 
to establish this is 1400 (which is what MTU value my dhcp server 
issues).

ideally what I want to do is have that converted from hexadecimal 
to decimal in the code, but as quite the noob, I cant figure it 
out.

any tips?
Aug 24 2014
next sibling parent "Nicolas Sicard" <dransic gmail.com> writes:
On Monday, 25 August 2014 at 06:57:48 UTC, confused wrote:
 hi team!

 I'm using this swift piece of code to seek out the Option 26 
 DHCP is deploying and output to the screen: 
 https://github.com/CyberShadow/dhcptest/blob/master/dhcptest.d
 (props for code CyberShadow).

 When I get the value it says 0578. I've used an online 
 converter to establish this is 1400 (which is what MTU value my 
 dhcp server issues).

 ideally what I want to do is have that converted from 
 hexadecimal to decimal in the code, but as quite the noob, I 
 cant figure it out.

 any tips?
You can use std.format: import std.format; auto data = "0578"; auto spec = singleSpec("%X"); assert(data.unformatValue!uint(spec) == 1400); (you should probably use the D.learn forum for this kind of question)
Aug 25 2014
prev sibling parent reply "hane" <han.ehit.suzi.0 gmail.com> writes:
On Monday, 25 August 2014 at 06:57:48 UTC, confused wrote:
 hi team!

 I'm using this swift piece of code to seek out the Option 26 
 DHCP is deploying and output to the screen: 
 https://github.com/CyberShadow/dhcptest/blob/master/dhcptest.d
 (props for code CyberShadow).

 When I get the value it says 0578. I've used an online 
 converter to establish this is 1400 (which is what MTU value my 
 dhcp server issues).

 ideally what I want to do is have that converted from 
 hexadecimal to decimal in the code, but as quite the noob, I 
 cant figure it out.

 any tips?
Try std.conv.to. to!int("0578", 16) == 1400
Aug 25 2014
parent "Nicolas Sicard" <dransic gmail.com> writes:
On Monday, 25 August 2014 at 07:37:59 UTC, hane wrote:
 On Monday, 25 August 2014 at 06:57:48 UTC, confused wrote:
 hi team!

 I'm using this swift piece of code to seek out the Option 26 
 DHCP is deploying and output to the screen: 
 https://github.com/CyberShadow/dhcptest/blob/master/dhcptest.d
 (props for code CyberShadow).

 When I get the value it says 0578. I've used an online 
 converter to establish this is 1400 (which is what MTU value 
 my dhcp server issues).

 ideally what I want to do is have that converted from 
 hexadecimal to decimal in the code, but as quite the noob, I 
 cant figure it out.

 any tips?
Try std.conv.to. to!int("0578", 16) == 1400
Yes, that's a bit simpler than my solution :-P
Aug 25 2014