Hi all,
i am new to this forum, but i need a help, i need to increment BIT values of 0-4 without disturbing other bits in a byte, Because others bits 5,6,7 is already set, so i just need to increment the remaining bits whenever and entry is found. for ex when i find a entry, it must increment the bit values from 0-4 without disturbing the rest of the bits. can anybody help me out
6 2212
Hi all,
i am new to this forum, but i need a help, i need to increment BIT values of 0-4 without disturbing other bits in a byte, Because others bits 5,6,7 is already set, so i just need to increment the remaining bits whenever and entry is found. for ex when i find a entry, it must increment the bit values from 0-4 without disturbing the rest of the bits. can anybody help me out
Try by using bitwise OR
Example :
X | 1 will set the 1bit and existing bits will be same only change is 1st bit will set
X | 2 will set second bit
X | 3 will set 1st and 2nd bit ......
Thanks and Regards
Rajesh G
rajeshg@infotechsw.com
It depends whether big-indian or small indian.. in my case
for example: -
-
0010 0000 = (32 in dec ) = (space in ascii)
-
-
you want to leave the first 4 bit as is.. and want to edit the 4 last bit into something like 0010.. this should become 0010 0010.. therefore because -
-
0010 0010 = (34 in dec ) = "(quote) in ascii
-
-
then thats it.. you've changed the last 4 bit without changing the first 4..
NOTE: This is what i've done somehow when i was in high school and now im kinda not into that cause im using high level language.. im just here to reminisce C.. Also be careful with unsigned char and char cause they really differ unsigned char can carry up to 255 but char is only up to 127..
Wait for the powerful ones in the forum they can answer you in a more easy practical way just like the answer above.. :)
hi,
sorry for my delay reply, thanks for your reply, but i need to increment the bits 0-4 without disturbing other 3 bits in a byte whenever i find an entry in a list
Try by using bitwise OR
Example :
X | 1 will set the 1bit and existing bits will be same only change is 1st bit will set
X | 2 will set second bit
X | 3 will set 1st and 2nd bit ......
Thanks and Regards
Rajesh G
rajeshg@infotechsw.com
Thanks Rajesh, i need to increment the bits whenever i find an entry in a list, the setting of bits is fine, how to increment???
Thanks Rajesh, i need to increment the bits whenever i find an entry in a list, the setting of bits is fine, how to increment???
the following should increment bits 0-3 of n without effecting bits 4-7 -
int temp=(n&0xf); // get bits 0-3
-
// increment bits 0 to 3 and add in bits 4-7
-
n=(n & 0xf0) + ((++temp) & 0xf);
-
the following should increment bits 0-3 of n without effecting bits 4-7 -
int temp=(n&0xf); // get bits 0-3
-
// increment bits 0 to 3 and add in bits 4-7
-
n=(n & 0xf0) + ((++temp) & 0xf);
-
hi thank you for your suggestion, its working fine, i just modified
thank you all for your help
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Bryan Parkoff |
last post by:
I have two variables: "char A" and "short B". I can be able to convert
from A to B using explicit case conversion with no problem like "B = short
(A);". Right now, I have two variables: "char T"...
|
by: Samuel Thomas |
last post by:
Hello Friends,
I understand(could be wrong) that the smallest chunk of memory is
called a word. If that is correct, that means if I am using a 32 bit
OS a word is 4 bytes. So that's why the size...
|
by: rahul |
last post by:
Hi!,
I have a java program that receives data via sockets from a C program.
The java program has to recieve the data in byte format. I need to
send character arrays from the C side after...
|
by: Ben Terry |
last post by:
What's the most efficient way to transfer data from a byte to a struct?
The struct is rather complex--contains other structs as well as byte
members. I've tried to use Marshal.Copy and an IntPtr...
|
by: Ekim |
last post by:
hello,
I'm allocating a byte-Array in C# with byte byteArray = new byte;
Now I want to pass this byte-Array to a managed C++-function by reference,
so that I'm able to change the content of the...
|
by: david ullua |
last post by:
I am reading "Joel on Software" these days, and am in stuck with the
question of "how to calculate bitsize of a byte" which is listed as one
of the basic interview questions in Joel's book. Anyone...
|
by: Ajay |
last post by:
Hi all,can you please tell the most efficient method to reverse a
byte.Function should return a byte that is reversed.
|
by: =?Utf-8?B?U2hhcm9u?= |
last post by:
Hi Gurus,
I need to transfer a jagged array of byte by reference to unmanaged
function, The unmanaged code should changed the values of the array, and when
the unmanaged function returns I need...
|
by: ThunderMusic |
last post by:
Hi,
The subject says it all... I want to use a byte and use it as byte* so I
can increment the pointer to iterate through it.
What is the fastest way of doing so in C#?
Thanks
ThunderMusic
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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....
|
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...
|
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...
| |