473,320 Members | 1,831 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How to put two unsigned char together and build another number .

1
I was wondering if some one could help me.
I need to put two unsigned char (8bits) near each other and make another number of it.
For example:
Binary 00000001 (1 dec)
Binary 00000010 (2 dec)
Binary result
0000000100000010 (258 dec)
I would like to put them together in the way that I would not loose any bits.
Jan 9 '07 #1
3 2549
RedSon
5,000 Expert 4TB
You might want to checkout MAKEWORD assuming you are using a windows system. Search TechNet for "MAKEWORD"

Otherwise you can make your own MAKEWORD macro. Its kinda spiffy!
Jan 9 '07 #2
horace1
1,510 Expert 1GB
I was wondering if some one could help me.
I need to put two unsigned char (8bits) near each other and make another number of it.
For example:
Binary 00000001 (1 dec)
Binary 00000010 (2 dec)
Binary result
0000000100000010 (258 dec)
I would like to put them together in the way that I would not loose any bits.
you can bit shift one of the values 8 bits left and add the other value
e.g.
Expand|Select|Wrap|Line Numbers
  1.     int i=1, j=2;
  2.     int k=(i << 8) + j;
  3.  
Jan 9 '07 #3
You can also multiply by 256 ( 16^2) the first char then sum the second :

int a, b,c;
a=1; b=2;
c=(a*256)+b;





you can bit shift one of the values 8 bits left and add the other value
e.g.
Expand|Select|Wrap|Line Numbers
  1.     int i=1, j=2;
  2.     int k=(i << 8) + j;
  3.  
Jan 9 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: bonham | last post by:
i m a beginner in C++. I have some questions: what is static_cast<unsigned>? i saw someone use static_cast<unsigned> and static_cast<unsigned char> together. why? e.g....
1
by: b83503104 | last post by:
When are they not consistent?
10
by: tinesan | last post by:
Hello fellow C programmers, I'm just learning to program with C, and I'm wondering what the difference between signed and unsigned char is. To me there seems to be no difference, and the...
16
by: TTroy | last post by:
Hello, I'm relatively new to C and have gone through more than 4 books on it. None mentioned anything about integral promotion, arithmetic conversion, value preserving and unsigned preserving. ...
1
by: sharmadeep1980 | last post by:
Hi All, I am facing a very unique problem while compling my project in "Release" build. The project is building in DEBUG mode but giving linking error on Release build. Here is the error:...
6
by: Bobrick | last post by:
Hi. Thanks to everyone who replied to my last post, it turns out it wasn't the line where I was trying to treat the variable in question as an array which was the problem, but the line above. ...
12
by: Martin Wells | last post by:
I'm trying to come up with a fully-portable macro for supplying memset with an unsigned char rather than an int. I'm going to think out loud as I go along. . . I'll take a sample system before I...
6
by: Kislay | last post by:
Consider the following code snippet unsigned int i=10; int j= - 2; // minus 2 if(i>j) cout<<"i is greater"; else cout<<"j is greater"; Since i is unsigned , j is greater . I know why , but...
29
by: Kenzogio | last post by:
Hi, I have a struct "allmsg" and him member : unsigned char card_number; //16 allmsg.card_number
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.