473,836 Members | 1,586 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Bit mask

Als
What's an efficient way to mask a last 3 bits of a 8-bit char and make them
all zero?

Bit-shifting is possible but not sure if it is efficient enough.

Example:

01011[010] --> 01011[000]

Thanks!
Nov 14 '05
24 25850
Alexander Bartolich <al************ *****@gmx.at> wrote:
begin followup to Christopher Benson-Manica:
Is ~7 guaranteed to be ...111111111110 00 on all systems?


Well, on a machine running trinary logic ... perhaps using three
charge states of an atom ... where the decimal number '7' is
represented by the digits '21' ... well, how the fuck is bitwise
negation meant to work there?


Slowly. But it must, because the Standard requires it.

If you ever find a ternary computer with a C compiler, warn me, I could
do with a laugh.

Richard
Nov 14 '05 #21
pete <pf******@minds pring.com> wrote in message news:<3F******* ***@mindspring. com>...
Peter Nilsson wrote:
Eric Sosman <Er*********@su n.com> wrote in message news:<3F******* ********@sun.co m>...
Christopher Benson-Manica wrote:
>
> Eric <eg************ *@verizon.net> spoke thus:
>
> > x = x & ~7;
>
> Is ~7 guaranteed to be ...111111111110 00 on all systems?

Yes. There's this pettifogging possibility, though,
that ...1111000 could be a trap representation for `int'
(as far as I know, the only platform for which this is
true is the Deathstation 9000, and then only on alternate
Thursdays when the moon is full). For 100% safety, you
could write `~7u' instead.


Well, if you think that ~ can change padding bits,
then ~7u isn't safe either, since even unsigned types can have
padding, and hence, potential trap representations
(apart from the uintN_t types of course).


He may have been refering to negative zero, instead of padding bits.

In C99 there's only 3 formats for representing negative integers,
but in C89, the representation for negative integer values
is only specified in broad terms relating to sign and value bits,
which would allow an implementation to define any particular
negative integer value representation, as negative zero.


I'm not with you! How is ~7 a negative zero in C89? As I understood
it, there were no trap representations in C89, irrespective of the
representation chosen.

--
Peter
Nov 14 '05 #22
Peter Nilsson wrote:
How is ~7 a negative zero in C89?


The C89 standard does not specify the representation
for the magnitudes of negative integer values.

--
pete
Nov 14 '05 #23
"pete" <pf*****@mindsp ring.com> wrote in message
news:40******** ***@mindspring. com...
Peter Nilsson wrote:
How is ~7 a negative zero in C89?


The C89 standard does not specify the representation
for the magnitudes of negative integer values.


But the responses in DR#069, although rather cryptic (both the questions and
responses are rather carelessly mislabled), seems to rule out the
possibility of ~7 being a 'negative zero'.

Given the committee's interpretation of "pure binary numeration system", I'm
not sure what other systems are actually allowed apart from the common 3
(padding bits and 'holes' notwithstanding ).

That said, I'm more than happy to stick to the golden rule of not using
signed integers for bit manipulations whenever the sign bit is, or could
become, 1. :-)

--
Peter
Nov 14 '05 #24
Peter Nilsson wrote:

"pete" <pf*****@mindsp ring.com> wrote in message
news:40******** ***@mindspring. com...
Peter Nilsson wrote:
How is ~7 a negative zero in C89?
The C89 standard does not specify the representation
for the magnitudes of negative integer values.


But the responses in DR#069,
although rather cryptic (both the questions and
responses are rather carelessly mislabled), seems to rule out the
possibility of ~7 being a 'negative zero'.


I don't see anything there which would prohibit
1111 1111 1111 1000 from representing negative zero.
Given the committee's interpretation of
"pure binary numeration system", I'm
not sure what other systems are actually
allowed apart from the common 3
(padding bits and 'holes' notwithstanding ).


The systems which are allowed in C89 are not specified by name,
so any system which uses the sign bit for negative values
followed by any systematic representation of the magnitudes,
would have been valid in C89.

--
pete
Nov 14 '05 #25

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

Similar topics

1
6366
by: Miranda Evans | last post by:
In my application, a text box control resides in a form. The text box control is unbound, but--assuming all edits are passed when the user click a command button on the form--the contents of the text box control end up in a field in a table with a data type of Date/Time. Is it possible to set up a mask on this text box control such that if one types any any of the following sequence of characters into the text box 06/25/04 6/25/04
9
2974
by: Paul | last post by:
hi, is there an input mask i could use on a report to do the following: (1) if i enter "THISISATEST" on my form, i want the text box on my report to display: "T H I S I S A T E S T". (2) if i enter "THIS IS A TEST" on my form, i want the text box on my report to display: "T H I S I S A T E S T".
11
4438
by: MS | last post by:
The simplest input mask for peoples names is.... >L<?????????????? But what about when you have names like MacDonald, or Mary-Anne? Anyone come up with a good "all round" "idiots" mask that still applies capitals and lower case when required - even for Mac and hyphens?
2
3729
by: johnp | last post by:
Hi, Our Tech department updated users to Office 2003 this week. Now the input mask in one of the applications is showing up as: (###) ###-### The input mask wizard works correctly when I redo the mask. But in form view, the mask appears reverts to the previous.
7
7080
by: F. Michael Miller | last post by:
I have a db with Access front end, sql back, linked tables. I need to be able to change input masks at the table level in code. Any ideas? Thanks!
3
3346
by: AA Arens | last post by:
When I want the first character of a field to be Uppercased, I need to make an input mask, like >L< followed by ??????? for example. But this mask creates ____ in an unfilled field, which I don't like. How to get the fist character uppercased without an input mask or without ____ (underscores). When I click with the mouse on an empty field, it won't go to the far left side, cause of the input mask. How to avoid it? Bart
11
10516
by: ex laguna | last post by:
How do I find the lowest bit position of a mask using only macros? I want to do everything in compile time. That mean, there cannot be control statements such as if, while, for, etc. in the macro. Note that the macro takes only one (1) argument, the mask. Examples: // Mask Lowest bit position
1
1744
by: Matt | last post by:
I recently came across what I believe to be a peculiar bug with Mdi Children, and wanted to see if anyone else had experienced this before sending it in. The issue is as follows: I have a number of forms set up as children of a single "Shell" MdiParent. In these, I have a number of databound masked textbox controls (for phone numbers, 9-digit zips, etc...). When I show the form the first time, the masks show up fine; however, if I hide...
2
4283
by: Daniel Nogradi | last post by:
How does one do a histogram on only a part of an image? This is what I found in the PIL documentation about histogram( ): """ im.histogram(mask) =list Returns a histogram for those parts of the image where the mask image is non-zero. The mask image must have the same size as the image, and be either a bi-level image (mode "1") or a greyscale image ("L"). """
7
3529
desklamp
by: desklamp | last post by:
I'm a total Access newbie, please bear with me! Using Win2K/Access 2003. I'm trying to create a table in which I can store IP addresses and other information. According to Microsoft, there is no native way of converting an IP address to an integer/long number (which is much more efficient to index and search). After searching, I found a function which is able to take either an IP address or integer and convert it to the other. In the...
0
9814
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10838
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10585
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6977
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5645
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5821
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4447
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 we have to send another system
2
4010
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3111
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.