12

Convert a Long to base 36 to scala

 2 years ago
source link: https://www.codesd.com/item/convert-a-long-to-base-36-to-scala.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Convert a Long to base 36 to scala

advertisements

How can I convert a Long to base36 ? Along with your answer can explain how you came to the answer?

I've checked the scaladocs for Long for converting to a different base, and on converting a Long to a BigInt. I saw that BigInt does have toString( base ) so a solution could involve changing the type, but I couldn't figure out how.

Note: I'm new to scala / java / type-safe languages so I could be overlooking something trivial.


The class java.lang.Long has a static method toString(long i, int radix) which will convert a Long into a string representation of another base. "Radix" means the same thing as "base" in this context.

val myLong = 25000L
val longInBase36:String = java.lang.Long.toString(myLong, 36)

Scala will treat your scala Long value as a java.lang.Long when necessary, so you can always look for methods in the Java API documentation when necessary. See: http://docs.oracle.com/javase/6/docs/api/java/lang/Long.html

Related Articles

How to convert a long binary string to an integer in python? (base & gt; 36)

I have a bit string of length 128 and want to perform Bitwise AND on it. To do that, I want to first convert the bit string into a integer. int("00000010000....0000000",128) However, python gives an error: ValueError: int() base must be >= 2

how to convert an Iterator [Long] to Iterator [String] in scala

I have a requirement where I have to convert a Iterator[Long] to Iterator[String] in scala. Please let me know how can I do it ThanksWell just like any other collection use map. For example: scala> val ls = List(1,2,3).toIterator ls: Iterator[Int] =

Converting a Spark Data Frame to a Scala Map Collection

I'm trying to find the best solution to convert an entire Spark dataframe to a scala Map collection. It is best illustrated as follows: To go from this (in the Spark examples): val df = sqlContext.read.json("examples/src/main/resources/people.json&qu

How to convert format Long Value 20010203 to string 2001-02-03?

I have variable long. Example: long date = 20010203; I need to print value by cout in this format 2001-02-03.Example: cout << "Today is " << "2001-02-03" << endl; I need to convert value long 20010203 to string format

How to convert unsigned long string

In the C language, how do I convert unsigned long value to a string (char *) and keep my source code portable or just recompile it to work on other platform (without rewriting code? For example, if I have sprintf(buffer, format, value), how do I dete

How can I easily convert a line angle to a navigation scale (ie with a range of [0.360] and & ldquo; North & rdquo; = 0 deg)?

I have two points, (x1,y1) and (x2,y2), that I'd like to draw a line between. I know I can figure out the angle (in degrees) of that line using arctangent and the slope: atan((y2-y1)/(x2-x1))*180/pi However, how would I convert this angle to a [0,360

How to convert a long string into a binary string?

How can I convert a long long to an array of char's that match up in the binary values? I'm working on a program where a binary string is sent over a network to control a lighting system. The way I have it set up now is I have a function that receive

C ++: Convert a long unsigned interval to a vector & lt; uint8_t & gt; raw data

I need to convert a long int x = 0x9c758d0f into a vector<uint8_t> y = 9c 75 8d 0f. I was using: std::stringsteam ss; ss << std::hex << x; std::string s = ss.str(); std::vector<uint8_t> y; String2Vector(s,y); void String2Vector(std

A double javascript function to convert a long date and return today's date in mm-dd-aaa format

I need your help, I can't seem to find any other help on this on the internet, because it seems its either one way ot the other. What I would like to be able to do is to create a combined, two-fold javascript function that would convert a long date s

convert java.util.Map [String, Object] to scala.collection.immutable.Map [String, Any]

How do I convert java.util.Map[String, Object] to scala.collection.immutable.Map[String, Any], so that all values in the original map (integers, booleans etc.) are converted to the right value to work well in Scala.As VonC says, scala.collections.Jav

C ++: Converts unsigned long long int into vector & lt; char & gt; and vice versa

Can anyone tell me how to convert unsigned long long int into vector and vice versa. For converting from unsigned long long int to vector, I tried the following: unsigned long long int x; vector<char> buf(sizeof(x)); memcpy( &buf[0], &x, siz

Timestamping of the PHP Integer Database to the Long Java Base Timestamp

I get Integer timestamp from PHP program, but in Java timestamps are ing Long format. So how can I convert this PHP Integer timestamp to Java Long format and convert that long format to Date object?PHP timestamp is number of seconds since 1/1/1970, a

Convert a long .NET to an unsigned 8-byte integer

For the purposes of setting a value in Active Directory I would like to convert a long to an unsigned 8-byte integer, for assignment to an AD property. How can I do this?A simple cast can cause problems if the long is negative and may result in an Ov

How to convert a long Java to a * unsigned * base-X String (and back)?

[EDIT] I am NOT accepting any answer which involves BigInteger, or other similarly inefficient method. Please actually read the question before answering! Java, annoyingly enough, does not support unsigned number types. You can convert a byte, short

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK