473,324 Members | 2,193 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,324 software developers and data experts.

How to set each bit, if the variable is short

i am using the below logic. but it gives me error when i am setting the bit_position 15 or 16. i suspect, the problem with the integer range.
please suggest.
Expand|Select|Wrap|Line Numbers
  1. short bit_map, bit_position
  2.  
  3. bit_map = bit_map | ( 1 << bit_position )
Jan 3 '13 #1
2 1965
weaknessforcats
9,208 Expert Mod 8TB
A sort is 16 bits. Shifting 1 left by 16 bits won't work because the short is too small. Shifting 1 left 15 bits destroys the short's sign bit. Since most negative values are stored in 2's complement form, a 1 in the sign bit will cause the value t appear as a very large negative number. But you can avoid the sign bit problem by using an unsigned short.
Jan 3 '13 #2
I think U can use ':'the do this!
Jan 5 '13 #3

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

Similar topics

99
by: Glen Herrmannsfeldt | last post by:
I was compiling a program written by someone else about six years ago, and widely distributed at the time. It also includes makefiles for many different systems, so I know it has been compiled...
2
by: Avi Laviad | last post by:
hi, sorry for the dumb question but how do i code a bit variable in c? i mean - shoudlnt the synax need to be: bit j; j = 1; correct me if im wrong (and i suppose i am). Avi.
7
by: Partho | last post by:
I have a float variable which I need to add to a short variable. How do I do this? Do I have to typecast or is there a way around? I tried typecasting the float to a short, but that gives me a 0 or...
20
by: Manuel | last post by:
hi, I have a problem, a stupid problem. I can't declare a variable of type byte. The g++ said that i have syntactic error in this line. The code is this: byte * variable; well, i think...
4
by: rakesh.Mysore | last post by:
HI I have a problem in casting short to ushort in my project. i have a ushort value of 38,143 now it is converted into short value of 27,393 and stored in variable.(when i casted ushort to...
7
by: Z-Z | last post by:
Hi, I used the following macro to determine variable signed or not, but only find that it is useless for a short or char variable. I think that it might caused by value conversion rules. I used...
7
by: stefan.istrate | last post by:
I have a short int variable and I'm trying to read it with scanf("%d",&x); but I'm getting a warning message which sounds like this: warning: format '%d' expects type 'int*', but argument 2 has...
0
by: zman77 | last post by:
EDIT: -- forgot to mention... I am using Visual Studio 2005, on Win XP, on an intel machine Hi. This is my first post, though I've "lurked" for a while because I find these forums very helpful....
112
by: istillshine | last post by:
When I control if I print messages, I usually use a global variable "int silent". When I set "-silent" flag in my command line parameters, I set silent = 1 in my main.c. I have many functions...
0
by: PauloD | last post by:
public struct Character_Items { public short Armor; public short Helm; public short WeaponL; public short WeaponR; public short Pants; public short Boots; public short Gloves; public short...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
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...
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: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.