473,513 Members | 2,678 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Create a 32-bit integer from 2 16-bit integer

Hi, how to create a 32-bit integer from 2 16-bit integer?
Thanks
Tony
Nov 15 '05 #1
6 10463
Tony Liu <en*******@hotmail.com> wrote:
Hi, how to create a 32-bit integer from 2 16-bit integer?


Shift and or them:

int combined = (highBits << 16) | lowBits;

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too
Nov 15 '05 #2
Thanks, in addition, how to create a 64-bit integer from 2 32-bit integers?

Tony

"Jon Skeet" <sk***@pobox.com> wrote in message
news:MP************************@news.microsoft.com ...
Tony Liu <en*******@hotmail.com> wrote:
Hi, how to create a 32-bit integer from 2 16-bit integer?


Shift and or them:

int combined = (highBits << 16) | lowBits;

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too

Nov 15 '05 #3
1 loo roll
2. sticky tape
3. glue

--

Duncan McNutt
Microsoft Product Deactivation Team
--
"Tony Liu" <en*******@hotmail.com> wrote in message
news:Of**************@TK2MSFTNGP10.phx.gbl...
Hi, how to create a 32-bit integer from 2 16-bit integer?
Thanks
Tony

Nov 15 '05 #4
Tony Liu <en*******@hotmail.com> wrote:
Thanks, in addition, how to create a 64-bit integer from 2 32-bit integers?


Apply the same advice again - the only difference is that you have to
cast the int to long before shifting:

long combined = (((long)highBits)<<32) | lowBits;

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too
Nov 15 '05 #5
Thanks again, but how to get back the 2 32-bit integers from the 64-bit
integer?

Thanks in advance
Tony

"Jon Skeet" <sk***@pobox.com> wrote in message
news:MP************************@news.microsoft.com ...
Tony Liu <en*******@hotmail.com> wrote:
Thanks, in addition, how to create a 64-bit integer from 2 32-bit
integers?
Apply the same advice again - the only difference is that you have to
cast the int to long before shifting:

long combined = (((long)highBits)<<32) | lowBits;

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too

Nov 15 '05 #6
Tony Liu <en*******@hotmail.com> wrote:
Thanks again, but how to get back the 2 32-bit integers from the 64-bit
integer?


Just use & to mask bits and shift right appropriately. If this isn't
enough, please consult a book about bit shifting - I'm not going to
give you an answer for every single possible thing you might want to do
with bit shifting.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too
Nov 15 '05 #7

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

Similar topics

0
524
by: Randell D. | last post by:
Folks, I'm using MySQL 3.23.56-Max and I have several CREATE TABLEs similar to the following in structure (taken from my PHP script so ignore the double quotes and periods) "ID MEDIUMINT(10)...
8
4306
by: Brian S. Smith | last post by:
Hi gang, Please help. I've been through the Access help, searched the Web, and I can't seem to get a straight answer. As the Subject line suggests, I want to run a fairly simple VB/Access Sub...
6
5822
by: Ekim | last post by:
hy, I've got a quite simple application: one windows form that consists of a button, and as soon as the user hits the button a second form shall appear. The difficult thing about it is that I...
5
6732
by: Michael Sperlle | last post by:
Is it possible? Bestcrypt can supposedly be set up on linux, but it seems to need changes to the kernel before it can be installed, and I have no intention of going through whatever hell that would...
3
2643
by: devrobcom | last post by:
Anyone knowing a better way of creating a format string than this? WCHAR sw_arg; int val1, val2; WCHAR mstring; WCHAR inbuffer1 = L"-value1 100 -value2 1000 -string1 mystring\t"; int read_no2;...
0
1711
by: Patrick F | last post by:
I keep getting this error message and i don't know whats the problem is and how to solve it. I have a webproject with 2 components (dll) added to it. One is called PhotoGallery and one is called...
1
8908
by: Patrick F | last post by:
I keep getting this error message and i don't know whats the problem is and how to solve it. I have a webproject with 2 components (dll) added to it. One is called PhotoGallery and one is called...
1
1231
by: Bhavesh1978 | last post by:
hey guys.. im trying to create a table in mysql in phpmyadmin was wondering weather is it right or wrong CREATE TABLE `User`( email varchar(32), fname varchar(32), lname varchar(32), pass...
11
4058
by: raylopez99 | last post by:
Keep in mind this is my first compiled SQL program Stored Procedure (SP), copied from a book by Frasier Visual C++.NET in Visual Studio 2005 (Chap12). So far, so theory, except for one bug...
1
1623
by: reap76 | last post by:
I am trying to create a table that has two columns. If possible I'd like to do that usign two seperate INSERT statements. I am a complete rookie at sql and am learning as I go along. So, please...
0
7257
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7535
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...
0
7521
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5682
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
5084
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
4745
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
3221
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1591
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
798
muto222
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.