473,471 Members | 1,716 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

unsigned 64-bit int / signed 64-bit int

It seems as though java does not have the ability to read or handle
unsigned 64-bit integers. Correct me if I am wrong. I am trying to
develop an algorithm to bypass this limitation.

Suppose I have the usigned 64-bit int "18438013886959845375". This
number falls between (2 ^ 64) - 1 and (2 ^ 63) - 1, meaning it is a
valid unsigned 64-bit integer, but higher than what java can handle.

All I need are the appropriate bits in this number, not the number
itself. I can read "18438013886959845375" in as a string correctly. Can
anyone help with an algorithm to convert an unsigned 64-bit integer
represented as a string, into a signed 64-bit integer (2's compliment)
with the exact same bit pattern, so that java can ingest it properly
and read the bits.

Example:

input "18438013886959845375" (a string)
Output X (where X is a number java can handle, and X and
18438013886959845375 have the exact same bit sequence)

Thanks in advance.

Jul 17 '05 #1
1 11528
No Such Luck wrote:
It seems as though java does not have the ability to read or handle
unsigned 64-bit integers. Correct me if I am wrong. I am trying to
develop an algorithm to bypass this limitation.

Suppose I have the usigned 64-bit int "18438013886959845375". This
number falls between (2 ^ 64) - 1 and (2 ^ 63) - 1, meaning it is a
valid unsigned 64-bit integer, but higher than what java can handle.

All I need are the appropriate bits in this number, not the number
itself. I can read "18438013886959845375" in as a string correctly. Can
anyone help with an algorithm to convert an unsigned 64-bit integer
represented as a string, into a signed 64-bit integer (2's compliment)
with the exact same bit pattern, so that java can ingest it properly
and read the bits.

Example:

input "18438013886959845375" (a string)
Output X (where X is a number java can handle, and X and
18438013886959845375 have the exact same bit sequence)


This may not be exactly what you want but you may want to look at
java.math.BigInteger, specifically the method toByteArray().

HTH,
Ray

--
XML is the programmer's duct tape.
Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Goran | last post by:
Hi! I need to convert from a unsigned char array to a float. I don't think i get the right results in the program below. unsigned char array1 = { 0xde, 0xc2, 0x44, 0x23}; //I'm not sure in...
34
by: Andy | last post by:
Hi, Are 1 through 4 defined behaviors in C? unsigned short i; unsigned long li; /* 32-bit wide */ 1. i = 65535 + 3; 2. i = 1 - 3; 3. li = (unsigned long)0xFFFFFFFF + 3; 4. li = 1...
14
by: mr_semantics | last post by:
I have been reading about the practise of casting values to unsigned char while using the <ctype.h> functions. For example, c = toupper ((unsigned char) c); Now I understand that the standard...
9
by: luke | last post by:
Hi everybody, please, can someone explain me this behaviour. I have the following piece of code: long long ll; unsigned int i = 2; ll = -1 * i; printf("%lld\n", ll);
4
by: cdrom205 | last post by:
static void MDString ( unsigned char *input) { MD5_CTX context; unsigned char digest; unsigned int len = sizeof(input);//strlen (const char*) md5.MD5Init (&context); md5.MD5Update...
3
by: tutush | last post by:
Hi there, I have problem with importing my C++ code to C#. The c++ looks like these extern _declspec(dllexport) const char* SendAndReceiveBufferedWrp(__int64 hConnection, const char*...
26
by: =?gb2312?B?wNbA1rTzzOzKpg==?= | last post by:
i wrote: ----------------------------------------------------------------------- ---------------------------------------- unsigned char * p = reinterpret_cast<unsigned char *>("abcdg");...
6
by: CFAN | last post by:
Here is a example of double-type-conversion char * __cdecl _itoa ( int val, char *buf, int radix ) { if (radix == 10 && val < 0) xtoa((unsigned long)val, buf, radix, 1); else
14
by: moumita | last post by:
Hi All, I need to convert 4 bytes to an unsigned long. Suppose I have one array like unsigned char buf.I need to convert these 4 bytes into a single unsigned long. Is the following piece of code...
20
by: Junmin H. | last post by:
Hello, I am trying to print the range of unsigned char and unsigned int. The one for char is working good, gives me a correct output, however the other one for int doesnt, why?? Thanks #include...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.