int

How to display a hex/byte value in Java

帅比萌擦擦* 提交于 2019-12-23 20:14:57
问题 int myInt = 144; byte myByte = /* Byte conversion of myInt */; Output should be myByte : 90 (hex value of 144). So, I did: byte myByte = (byte)myInt; I got output of myByte : ffffff90 . :( How can I get rid of those ffffff s? 回答1: byte is a signed type. Its values are in the range -128 to 127; 144 is not in this range. There is no unsigned byte type in Java. If you are using Java 8, the way to treat this as a value in the range 0 to 255 is to use Byte.toUnsignedInt : String output = String

Linq Stored Procedure Issue- Returning an int

霸气de小男生 提交于 2019-12-23 18:13:46
问题 I am trying to call a stored procedure with Linq, the stored procedure returns the value fine in SQL, but when I drag it onto my DBML file and try and call it from my code it is returning the Could not find an implementation of the query pattern for source type 'int'. 'Select' not found. I've looked at other threads and other stored procedures I have and for some reason rather than using an ISingleResult this is different and I cant seem to change the Return Type either. This is the DBML code

Converting an int into a base 2 cstring/string

£可爱£侵袭症+ 提交于 2019-12-23 16:34:28
问题 In visual studio on my PC I can use itoa() to convert from a base ten int to a base 2 c-string. However when I am on a Linux machine that function isn't supported. Is there another quick way of doing this kind of conversion? I know how to use a string stream and I can use the dividing and modding to convert to another base manually. I was just hopping that there was an easier way of accessing the binary representation of an int. 回答1: You could use std::bitset<N> with a suitable N (e.g., std:

Arduino: String to int gets strange values

怎甘沉沦 提交于 2019-12-23 16:01:59
问题 I want to convert a String to an int , and all I could find is that you have to convert the String to a char array and then cast this array to an int , but my code produces strange values and I can't figure out what the problem is. void ledDimm(String command) { // Get the Value xx from string LEDDimm=xx String substring = command.substring(8, command.length()); Serial.println("SubString:"); Serial.println(substring); Serial.println("SubString Length:"); Serial.println(substring.length()); //

Program to figure out number between 1 and 100 won't ever guess “100” because of rounding

不羁岁月 提交于 2019-12-23 15:29:46
问题 I'm just getting started with C++. I wrote a small program that chooses a random number between 1-100, and then modified it to make the program figure out the number (and count the number of guesses required). Everything in the program works, except for one thing. I'm using a formula that guesses the difference between the current guess and the previous highest/lowest value, so for a guess that's too low: low = guess; guess = (( guess + high ) / 2); It works great for all numbers except for

Operator '&&' can't be applied to operands of type 'int' and 'bool'

无人久伴 提交于 2019-12-23 13:16:08
问题 im trying to find out if a number that is entered is both divisible by 9 and 13, but it wont let me use the operator i need, i know the variable types are wrong but i dont know how to make it so that the variable types are accepted, im new to coding so can the answer be as basic as possible without taking the piss public bool IsFizzBuzz(int input) { if ((input % 9) && (input % 13) == 0) { return true; } else { return false; } } 回答1: Since == operator has higher precedence than && operator,

Is using int + “” bad for converting Java int's to Strings?

╄→гoц情女王★ 提交于 2019-12-23 13:13:29
问题 So our computer science teacher taught us how to convert int s to String s by doing this: int i=0; String s = i+""; I guess he taught it to us this way since this was relatively basic computer science (high school class, mind you), but I was wondering if this was in some way "bad" when compared to: int i=0; String s = Integer.toString(i); Is it more costly? Poor habit? Thanks in advance. 回答1: In theory The instruction String s = i + ""; does the following: convert i to String by calling

Why cannot save INT to SharedPreferences?

回眸只為那壹抹淺笑 提交于 2019-12-23 10:08:07
问题 I have a strange problem. I have never had it before. When I try to save int value to my SharedPreference and then restore in other Activity. Value is always 0 even if I save there other value (for example: 1); private String Number; private String Profile; and then saving values (in this case "1") to SharedPreferences in first Activity: SharedPreferences a = FirstActivity.this.getSharedPreferences("a", MODE_PRIVATE); SharedPreferences.Editor prefsEditorProfiles = a.edit();

int to long assignment

岁酱吖の 提交于 2019-12-23 06:56:59
问题 I have been trying this int and long conversion where I have tried assigning an int variable to a long variable. The code is as follows: public static void main(String []args){ int i = 1024; long j = i; long k = i*i*i*i; System.out.println("j= " +j+ ", k= " +k); } So, while printing j , it simply gave an output of 1024 . But while printing k , it showed an overflow ( k =0). I sorted out this problem by using this technique, where I have explicitly casted each i to long . i.e. public static

How to extract numbers from textview android studio

随声附和 提交于 2019-12-23 05:13:07
问题 I have a textview in my app that contains numbers and letters and what I want to do is only get the numbers from it and apply a if statement. Something along the lines of; if (number == 1) { // do something } else if (number == 2) { // do something } else if (number >= 8) { // do something } I have declared my textview like this; TextView textview = (TextView) findViewById(R.id.number); and the textview will contain texts similar to theses textview.setText("1\nperson"); textview.setText("2