tostring

Java.lang.Integer类中toString(int i, int radix)的具体实现

匆匆过客 提交于 2019-12-02 02:34:29
Java.lang.Integer.toString(int i,int radix)方法可以实现将一个int类型的10进制的数据转换为指定进制的数据。 api文档中介绍: 返回第二个参数指定的基数中第一个参数的字符串表示形式。 如果基数小于Character.MIN_RADIX(2)或大于Character.MAX_RADIX(36),则改用基数10。 如果第一个参数为负,则结果的第一个元素为前加上一个负号“-”。如果第一个参数不为负,则结果中不会出现负号。 结果的其余字符代表第一个参数的大小。如果大小为零,则用单个零字符'0'表示;否则,表示幅度的第一个字符将不是零字符。如果基数为N,则按所示顺序将这些字符的前N个用作基数N个数字。因此,十六进制的数字(基数16)为0123456789abcdef。如果需要大写字母,可以在结果上调用String.toUpperCase()方法: Integer.toString(n,16).toUpperCase() toString(int i,int radix)方法的源码: public static String toString(int i, int radix) { /* 最大进制36,最小进制2,见Character类*/ if (radix < Character.MIN_RADIX || radix > Character

Creating a custom format string in a dataGridView

余生长醉 提交于 2019-12-02 02:01:17
问题 I have a dataGridView whose dataSource is a dataTable. My problem is that I want certain columns to be displayed in Hex. I can get that far with using something like this: foreach (DataGridViewColumn c in grid.Columns) { if (DISPLAYED_IN_HEX.Contains(c.Name)) { c.DefaultCellStyle.Format = "X"; } } My issue though is that I want this hex value prepended with 0x so as not to confuse anyone that they are in hexidecimal form. The values in the dataTable are various integral types. I looked into

Override toString in a Scala set

て烟熏妆下的殇ゞ 提交于 2019-12-02 00:08:49
I want to create a set of integers called IntSet . IntSet is identical to Set[Int] in every way except that its toString function prints the elements as comma-delimited (the same as if you called mkString(",") ), and it has a constructor that takes a Traversable of integers. What is the simplest way to do this? > IntSet((1 to 3)).toString 1,2,3 I'd think there would be some one-line way to do this, but I've been fiddling around with implicit functions and extending HashSet and I can't figure it out. The trick is to use a proxy object. Eastsun has the answer below. Here's a slightly different

JavaScript Bitwise Masking

北慕城南 提交于 2019-12-01 22:04:44
This question is similar to this other question ; however, I'd like to understand why this is working as it is. The following code: console.log((parseInt('0xdeadbeef', 16) & parseInt('0x000000ff', 16)).toString(16)); console.log((parseInt('0xdeadbeef', 16) & parseInt('0x0000ff00', 16)).toString(16)); console.log((parseInt('0xdeadbeef', 16) & parseInt('0x00ff0000', 16)).toString(16)); console.log((parseInt('0xdeadbeef', 16) & parseInt('0xff000000', 16)).toString(16)); console.log((parseInt('0xdeadbeef', 16) & parseInt('0x000000ff', 16)).toString(16)); console.log((parseInt('0xdeadbeef', 16) &

How to pass variables to overridden toString() method?

人走茶凉 提交于 2019-12-01 20:52:53
Is it possible to pass in a bool variable into an overridden toString() method, so it can conditionally print the object in different formats? You can define overload method of ToString() . public string ToString(bool status){ // } The typical pattern for parametrized ToString() is to declare an overload with a string parameter. Example: class Foo { public string ToString(string format) { //change behavior based on format } } For a framework example see Guid.ToString If you are talking about your own class, you could do the following: public class MyClass { public bool Flag { get; set; }

JavaScript Bitwise Masking

心不动则不痛 提交于 2019-12-01 19:22:59
问题 This question is similar to this other question; however, I'd like to understand why this is working as it is. The following code: console.log((parseInt('0xdeadbeef', 16) & parseInt('0x000000ff', 16)).toString(16)); console.log((parseInt('0xdeadbeef', 16) & parseInt('0x0000ff00', 16)).toString(16)); console.log((parseInt('0xdeadbeef', 16) & parseInt('0x00ff0000', 16)).toString(16)); console.log((parseInt('0xdeadbeef', 16) & parseInt('0xff000000', 16)).toString(16)); console.log((parseInt(

How can I determine if an object can ToString into value or type name?

亡梦爱人 提交于 2019-12-01 19:12:17
I am writing an interop between a php service and our crm. One of the things I need to do is make sure that simple types get converted ToString() for use later in a json converter. I am not sure even what the name is for 'simple types' but it can be defined like this... "an object that represents a low level variable type, containing a single value, not a class or anything with executable functions etc" I've found that int, string, bool, double, and surprisingly enum will ToString() with pretty predictable results. int x = 0; bool y = true; double z = 1.59 // money CustomEnum theEnum =

Java ArrayList / RMI

拟墨画扇 提交于 2019-12-01 17:57:39
问题 I've built a simple item class; class itemInfo{ int auctionID; int startPrice; int buyoutPrice; } I've created an ArrayList; ArrayList<itemInfo> itemSet = new ArrayList<itemInfo>(); I also have a method here that allows a user to create an item (the method is incomplete, I've only tried implementing choice == 1 so far!); public void auctionChoice(){ System.out.println("---- What would you like to do? ----\n"); System.out.println("1: List an item for auction\n"); System.out.println("2: Bid on

window.toString.call is undefined in IE8

亡梦爱人 提交于 2019-12-01 17:36:07
问题 When you run: window.toString.call("") everything's fine in FF/CH but in IE8 you get a script error. Investigating a bit more it turned out, that window.toString.call is undefined in IE8? You can also run this one: window.toString instanceof Function; // false alert(window.toString); // function toString() { // [native code] // } Why is that and how to solve it? And I started wondering how come jQuery works in the first place? 回答1: window is a host object, and the ECMAScript Language

How make toString() method return Super Class private fields also along with its instance fields?

六月ゝ 毕业季﹏ 提交于 2019-12-01 17:32:19
Is there a way to make toString() include private fields of the super class ? I tried adding a super.toString() , no use however. Please see the code below Employee.java package test; public class Employee { private String name; private int id; private double salary; public Employee(String name, int id, double salary) { super(); this.name = name; this.id = id; this.salary = salary; } public double getSalary() { return salary; } @Override public String toString() { return "Employee [name=" + name + ", id=" + id + ", salary=" + salary + "]"; } public static void main(String[] args) { Employee e