Unsigned int to integer conversion
Hi,
I have an unsigned integer column in my database table. If I try to retreive the value of the column using resultset.getInt() I'm getting "Numeric value overflow" error as it exceeds the INT_MAX value.
For eg., if the column value : 4294967295, the expected value from resultset.getInt() is -1 or Numeric Value Overflow error ?
Is it valid to retrieve the value using getInt() or should I use getLong()?.
Kindly Clarify.
Thanks,
Radhika.
use getLong
Similar Messages
-
No warning when assigning to an unsigned char from unsigned int
Is this an error in VC++, or am I missing something? The following code should give two warnings for assigning to a smaller type, but only gives one: (compiled as 32 bit)
unsigned
char c;
unsigned
int i = 24;
// 32 bit unsigned integer
unsigned
long L = 25;
// Also a 32 bit unsigned integer
c = L; // Warning C4244
c = i; // no warning
This happens in Visual Studios 2005, 2010, 2012, 2013 and 2015, at least.Is this an error in VC++, or am I missing something? The following code should give two warnings for assigning to a smaller type, but only gives one: (compiled as 32 bit)
unsigned
char c;
unsigned
int i = 24;
// 32 bit unsigned integer
c = i; // no warning
This happens in Visual Studios 2005, 2010, 2012, 2013 and 2015, at least.
Have you tried it with Warning Level 4?
In VC++ 2008 Express and W4 I get:
Warning 2 warning C4244: '=' : conversion from 'unsigned int' to 'unsigned char', possible loss of data
- Wayne -
Wrtie unsigned char and unsigned int into a binary file
Hi, I need write some data into some specific file format (.ov2) for other applications to read.
Here is the requirement of the data:
First byte: An unsigned char value, always "2" means simple POI entry
Next 4 byte: An unsigned int value,
Next 4 byte: A signed integer value.
Next 4 byte: A signed integer value
then next : A zero-terminated Ascii string
Here is my code:
String name = "name";
byte type = 2;
int size = name.length() + 13 +1; //1+4+4+4 and there is a 0 at last
int a = 1;
int b =2;
ds.writeByte(type); //1 byte, need save it as unsigned char
ds.writeInt(size); //4 //need to be an unsignged int
ds.writeInt(ilont); //4 //signed int
ds.writeInt(ilatt); //4 //signed int
//write zero-terminated ascii string
for(int n=0; n<name.length(); n++){
ds.writeByte(name.charAt(n));
ds.writeByte(0); This code could not get the correct result and I think I must do some sign to unsign conversion, but I don't know how to do it. Any help?
Thanks for you attention.You don't have to do anything special at all. What's in a int or a byte is what you, as a programmer, say it is. Java treats int's as signed but, in fact, with 2's complement arithmatic most operations are exactly the same. Load and store, add and subtract - it makes no difference whether a variable is signed or unsigned. It's only when you convert the number, for example to a wider type or to a string representation that you need to know the difference.
When you read an unsigned byte and you want to widen it to an integer you have to clip the top bytes of the integer e.g.
int len = input.get() & 0xff;This is because, since java sees a byte as signed it will extend the sign bit into the top bytes of the int. "& 0xff" forces them to zero.
Writing it, you don't have to do anything special at all - it will autmatically get clipped. The above is probably the only concesion you'll ever need to make to unsigned binary. (You'd need to do the same thing from unsigned int to long, but this almost never happens).
When I read ov2 files I used a mapped byte buffer, because it allows you to set either big-endian or little-endian and I wasn't sure which ov2 files used. (Sorry, I've forgotten). -
Converting from unsigned int / short to byte[]
Can anybody help me, I am trying to convert from:
- unsigned int to byte[]
- unsigned short to byte[]
I will appreciate your help lots. thanks.@Op.
This code converts an integer to a byte[], but you have to consider the byte order:
int value = 0x12345678;
byte[] result = new byte[4];
for (int i=3; i>=0; i--) {
result[i] = (byte)(value & 0xff);
value = value >> 8;
}This is another option:
int dummy = 7;
ByteArrayOutputStream os = new ByteArrayOutputStream();
os.write(dummy);
byte[] bytes = os.toByteArray();Kaj -
64bit unsigned int - j????
I have a 64bit unsigned int in a datastructure generated by a native method.
What would be the best java type to cast it to, before returning the value?
Thanks,
ThanBigInteger is the only java "datatype" that can handle this if you need to access the unsigned value within your Java code. None of the primitive datatypes will work as they are all signed.
The other alternative is to split the integer into 2 4 byte words and store them both in jlongs -
I tried opening it in safe mode and none of the other help tips in the database on firefox crashes when I open it apply to me. I also ran a couple of virus programs to check for any infections and found nothing. I had been having issues with java previous to firefox beginning to crash. So I attempted to uninstall java from my computer but it did not help.
My crash signature is PaintFrame(nsIRenderingContext*, nsIFrame*, nsRegion const&, unsigned int, unsigned int) and a search of this term on Mozilla Support pulled up no results.
I'm not terribly knowledgeable with programming so any suggestions would help!I read online about a "clean reinstall" of firefox which seems to have worked! They should include direction on this on their page: https://support.mozilla.com/en-US/kb/Firefox+crashes+when+you+open+it
-
I'm using Oracle 8.1.6 for Linux, and 7.3.4 on HP-UX. Compiler is gcc/g++ 2.95.2
In working with the Oracle precompiler on both HPUX and Linux, I've found a problem with the way that the Linux precompiler generates the sqlctx variable.
On linux, the following is generated when you run the precompiler:
static const unsigned int sqlctx = 1;
However, on HPUX, this is the corresponding code:
static unsigned long sqlctx = 10673468;
When you compile the Linux version with g++/c++ or aCC, you get fatal errors of this nature:
SQLSubsystem.cpp:562: passing `const unsigned int *' as argument 2 of `sqlcxt(void **, unsigned int *, sqlexd *, const sqlcxp *)' discards qualifiers
Is there a way to force the output of proc to leave off the const?
If you view the binary file proc, you can find the static unsigned int string listed. So I think it may be an option. However, I can't seem to turn it on.
Thanks-
Matt WrightAs for sqlctx:
sqlctx is a module identifier variable. i.e. if your project consists of multiple modules, each sqlctx should have different value.
I have seen this error only on Linux Pro*C starting of 8.1.5 version (have not tested 8.0.5 nor 8.1.6).
Anyway, I really can not understand why this error is not patched already.
As for constness:
I can not tell if there is an option which would solve such issue. I can only advise not to use -Werror option of gcc. It generates about 4-5 warnings per module, but it works ;-)) -
Help with unsigned ints and how to store and retrieve data in them
Hi all
I have a problem where some data is being stored in an unsigned int
i dont really know much about them and am unsure on how to go about using the data.
The data being stored in them is row and column information in an excel spreadsheet.
The method is passed through 2 ints (column, row) and then a unsigned int is created out of these two values
the column is 8 bits and shift to the left hand byte (column & 0xFF <<24)
the row is 16 bits shifted to the right of the column (row & 0XFFFF <<8)
so if the column and row were 1,1 then the unsigned int would be
16777472
and for 1,2 then it would be 16777728
(i dont actually know how these numbers are formed, it would be great if someone can explain this too :) )
anyway now i have those unsigned int numbers does anyone know how i would go about taking that unsigned int and getting my int back from it
so take 16777728 and extracting column 1, row 2
any help would be appreciatedits not a 3rd party product, its been written by
another peep who is on holiday for 2 weeks so im
trying to sort something out but dont really
understand unsigned ints and stuff :(This is what is called a "third party product". It's not written by Sun, and it's not written by you. -
Unsigned int - problem translating c++ function to java
OK so here's the deal:
I'm writing a client for a internet comunicator in java (J2ME to be precise). Unfortunately i have specs for this comunicator's protocol for c++ programing. The first problem I ran to is: I have to calculate a hash for a password so it doesn't go plain text on the network. The function in c++ that does this is:
int getPasswordHash(char *password, int seed){
unsigned int x=0, y=0, z=0;
char *pwd = password;
y = seed;
for (x = 0; *password; password++) {
x = (x & 0xffffff00) | *password;
y ^= x;
y += x;
x <<= 8;
y ^= x;
x <<= 8;
y -= x;
x <<= 8;
y ^= x;
z = y & 0x1f;
y = (y << z) | (y >> (32 - z));
cout << "Hash for \"" << pwd << "\" with seed \"" << seed << "\": " << y << "\n";
return y;
}My translation to java goes:
public int getPasswordHash(String password, int seed){
long x = 0, y = 0, z = 0;
int tmp = 0;
String pwd = password;
y = seed;
for (x = 0; x < password.length(); x++){
tmp = (int)x;
x = x | password.charAt(tmp);
y ^= x;
y = uintadd(y, x);
x <<= 8;
y ^= x;
x <<= 8;
y = uintsubst(y, x);
x <<= 8;
y ^= x;
z = y & 0x1f;
y = (y << z) | (y >> (32 - z));
x = tmp;
System.out.println("Hash for \""+ pwd + "\" with seed \"" + seed + "\": " + y);
return (int)y;
public long uintadd (long x, long y){
long xL = x & 0xffffffffL;
long yL = y & 0xffffffffL;
long sumL = xL + yL;
long sum = (sumL & 0xffffffffL);
return sum;
public long uintsubst (long x, long y){
long xL = x & 0xffffffffL;
long yL = y & 0xffffffffL;
long sumL = xL - yL;
long sum = (sumL & 0xffffffffL);
return sum;
}So I use the uintadd and uintsubst to add and substract values that should be unsigned int. Every operation works exactly like in c++ (I've checked) until this point:y = (y << z) | (y >> (32 - z));and to be exact (y << z) This doesn't turn out like in c++ so the whole function doesn't return the right vaule. I know it's because doing a bit operation on a unsigned int in c++ is different in than in java because unsigned variables have totally different bit values than signed ones. The question is: how to work this out. I managed to do aritmetic operations working but I have no idea how to deal with this. Any help would be great.I'm by no means the expert with this, but I'm going
to guess that this would work...
y = ((y << z) & 0xffffffffL) | (y >> (32 - z));
thus... to zero out the right shifted 1's before the
orWOW WOW WOW it totaly works thanks alot bsampieri !! -
How do i Send 8 and 16 bit unsign int througth the serial port
8 and 16 unsigned int througth the serial port
And How may pass 16 bit to my dac (datasheet attached) which desires serial data from 4 line (fig.8a pag.12) using parallel port (TTL compatible required)?
Any advice will be appreciated.
Paolo
Attachments:
dac714.pdf 132 KB -
Read/Write unsigned 32 bit integer to BLOB
Dear All,
I am writing an array of unsigned 32 bit integers to a Blob field, using delphi. I can also read the same from delphi.
In a stored proc, I need to read the unsigned 32 bit integer from the blob.
I have used dbms_lob.read function.
Here for dbms_lob.read(lob_loc,amount,offset,buffer)
I've given
lob_loc - the locator
amount - 4 bytes
offset - 1
buffer- ?? The buffer here has to be a datatype which corresponds to unsigned 32 bit. Which datatype in oracle can be used here ? I tried to give raw, but it doesnot seems to give the required out put.
Please help !!!What version of oraoledb? There were some issues with NUMBER datatype in earlier versions, I'd recommend testing the most recent version.
To patch 10.2 oraoledb, apply the 10.2.0.4 database patch to the client install.
Hope it helps,
Greg -
it crashes when i oen regularly and in safe mode.
problem happened after computer was returned from apple, refurbished (i.e., the hard drive was erased!)Seems to be handled in this bug report:
[https://bugzilla.mozilla.org/show_bug.cgi?id=597972 Bug 597972] – crash on startup [@ PL_DHashTableOperate | GCGraphBuilder::NoteRoot(unsigned int, void*, nsCycleCollectionParticipant*) ]
(please do not comment in bug reports) -
<pre><nowiki>Firefox 4.0.1 Crash Report [@ CD3DBase::DrawPrimitive(_D3DPRIMITIVETYPE, unsigned int, unsigned int) ]
Search Mozilla Support for Help
ID: df5fa277-41b2-46b3-9f02-2bf3f2110513
Signature: CD3DBase::DrawPrimitive(_D3DPRIMITIVETYPE, unsigned int, unsigned int)
Details
Modules
Raw Dump
Extensions
Comments
Correlations
Signature CD3DBase::DrawPrimitive(_D3DPRIMITIVETYPE, unsigned int, unsigned int)
UUID df5fa277-41b2-46b3-9f02-2bf3f2110513
Uptime 15.2 minutes
Last Crash 915 seconds (15.2 minutes) before submission
Install Age 527000 seconds (6.1 days) since version was first installed.
Install Time 2011-05-07 23:27:42
Product Firefox
Version 4.0.1
Build ID 20110413222027
Release Channel release
Branch 2.0
OS Windows NT
OS Version 5.1.2600 Service Pack 3
CPU x86
CPU Info GenuineIntel family 15 model 2 stepping 9
Crash Reason EXCEPTION_ACCESS_VIOLATION_WRITE
Crash Address 0x1
User Comments
App Notes AdapterVendorID: 10de, AdapterDeviceID: 02e0, AdapterDriverVersion: 6.14.12.7061
D3D10 Layers? D3D10 Layers-
D3D9 Layers? D3D9 Layers+
Processor Notes
EMCheckCompatibility True
Winsock LSP MSAFD Tcpip [TCP/IP] : 2 : 1 : MSAFD Tcpip [UDP/IP] : 2 : 2 : MSAFD Tcpip [RAW/IP] : 2 : 3 : RSVP UDP Service Provider : 6 : 2 : RSVP TCP Service Provider : 6 : 1 : MSAFD NetBIOS [\Device\NetBT_Tcpip_{D18F9393-8A72-4F22-AA8A-FEF9786EC28E}] SEQPACKET 4 : 2 : 5 : MSAFD NetBIOS [\Device\NetBT_Tcpip_{D18F9393-8A72-4F22-AA8A-FEF9786EC28E}] DATAGRAM 4 : 2 : 2 : MSAFD NetBIOS [\Device\NetBT_Tcpip_{32E7F2E7-2ED1-4450-8C6B-8DB1B597737D}] SEQPACKET 0 : 2 : 5 : MSAFD NetBIOS [\Device\NetBT_Tcpip_{32E7F2E7-2ED1-4450-8C6B-8DB1B597737D}] DATAGRAM 0 : 2 : 2 : MSAFD NetBIOS [\Device\NetBT_Tcpip_{A01D2C7A-0D97-4183-A5B1-A2FB8C008974}] SEQPACKET 1 : 2 : 5 : MSAFD NetBIOS [\Device\NetBT_Tcpip_{A01D2C7A-0D97-4183-A5B1-A2FB8C008974}] DATAGRAM 1 : 2 : 2 : MSAFD NetBIOS [\Device\NetBT_Tcpip_{532EB614-3BEA-4AF3-99AE-989D1B273FF9}] SEQPACKET 2 : 2 : 5 : MSAFD NetBIOS [\Device\NetBT_Tcpip_{532EB614-3BEA-4AF3-99AE-989D1B273FF9}] DATAGRAM 2 : 2 : 2 : MSAFD NetBIOS [\Device\NetBT_Tcpip_{269D4DF2-D033-4CCA-99B4-0EDBAC2A1D21}] SEQPACKET 3 : 2 : 5 : MSAFD NetBIOS [\Device\NetBT_Tcpip_{269D4DF2-D033-4CCA-99B4-0EDBAC2A1D21}] DATAGRAM 3 : 2 : 2 :
Adapter Vendor ID
Adapter Device ID
Bugzilla - Report this Crash
Crashing Thread
Frame Module Signature [Expand] Source
0 @0x2c07502
1 d3d9.dll CD3DBase::DrawPrimitive
2 d3d9.dll _allshl
3 xul.dll mozilla::layers::ImageLayerD3D9::RenderLayer gfx/layers/d3d9/ImageLayerD3D9.cpp:372
4 xul.dll mozilla::layers::ContainerLayerD3D9::RenderLayer gfx/layers/d3d9/ContainerLayerD3D9.cpp:330</nowiki></pre>*https://crash-stats.mozilla.com/report/index/df5fa277-41b2-46b3-9f02-2bf3f2110513
Try to disable hardware acceleration.
* Tools > Options > Advanced > General > Browsing: "Use hardware acceleration when available"
If disabling hardware acceleration works then check if there is an update available for your graphics display driver. -
Modbus real to unsigned integer conversion
Is there any alternative way of decoding the two unsigned integer 16 bit words received through Modbus when using reals? I am using the join numbers and type cast functions; however I am not able to download the complete Modbus list to a compact RIO with 32 MB RAM as it runs out of memory.
Khalid,
Thanks for your response. However, let me tell you more about my problem:
Basically my project consists of:
1. A list of shared variables within a library that also contains modbus slave with the communication settings.
2. (5) VIs that used to convert UInt16 to Single (for inputs) and Single to UInt16 (for otputs)
3. (1) VI to display information
As I try to download into a cRIO-9002 with 32MB of RAM, the device drops the communication and goes into safe mode, blinking the STATUS light 4 times, this means "run out of memory" .
I would like to know if there is any other alternative way to overcome this problem. Join and cast is functionally correct but it uses too much RAM -
I want to retrieve the data of a ResultSet by rs.getInt(3), but I need to convert this data to an Integer, because my PrimaryKey is in Integer format. How could I retrieve an Integer?
Integer MyInteger = new Integer(rs.getInt(3));
I want to retrieve the data of a ResultSet by
rs.getInt(3), but I need to convert this data to an
Integer, because my PrimaryKey is in Integer format.
How could I retrieve an Integer?
Maybe you are looking for
-
Old SD and MM documents shall be deleted on productive server
We have the situation that the same SD and MM documents sitting on two different productive servers. This is caused due to the migration from 4.0B to 4.7 some years ago. Some of our companies were kept on 4.0B with SD and MM enviroment on a separate
-
I keep updating my firefox whenever it prompts me to, and now I am using version 3.6.12, but I still cannot download any add-ons or have problem using youtube cause they still says I am using a older version of the browser. But when I go Help > About
-
SCCM report query that displays count of cpus per host and if host is physical or virtual
Hello, I have this query that displays the count of CPUs per host. How can I add a column to show if the host a physical or virtual? SELECT DISTINCT(CPU.SystemName0) AS [System Name], CPU.Manufacturer0 AS Manufacturer, CPU.Name0 AS Name, COUNT(CPU.R
-
How do I change facebook username in Ipad
How do I change my Facebook username in Ipad. My Ipad has my old Facebook account email address. I can't reactivate this email anymore, it was old company email. IPad Facebook app has still this old email account in memory and I can't delete the acco
-
Installing Windows 7 on Macbook Air W/O OSX
Hi guys, Long time reader, first time poster. I do heaps of work on Windows servers, etc so unfortunately I need to run Windows all the time for that. I have just purchased a new Macbook air Which arrives on monday. Ideally I would like to run only W