Win a copy of Serverless Applications with Node.js this week in the NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Ron McLeod
  • Tim Moores
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Vijitha Kumara

convert unsigned long based on hex value  RSS feed

 
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am trying to convert next code from C# to java

this code created a based 10 value, and increments it
is there a similar way to do it in java?
 
Saloon Keeper
Posts: 9997
208
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Peter Benda wrote:this code created a based 10 value


Nope, it doesn't. It parses a base 16 numeral, increments it, and then prints it as a base 16 numeral. Numbers don't have a base. Numerals (string representations of numbers) have a base.

Anyway, the methods you're looking for to do this are Long.parseLong(s, radix) and String.format(format, args). You will want to use "%010x" as the format string, but see the Formatter documentation to see why that is.
 
Marshal
Posts: 63843
209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I might prefer “%#010x” in the format String. More details in the same place as Stephan showed you.
 
bacon. tiny ad:
global solutions you can do at home or in your backyard
https://www.kickstarter.com/projects/paulwheaton/better-world-boo
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!