473,748 Members | 4,030 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

bit fiddling question by a newbie

14 New Member
I need your guidance as to how to approach this question.
I don't even know where to begin. It seems a bit general for me. Thanks alot.

Devise a function to test bits in a byte, and it returns
a) success or failure,
b) count of bits that are set (“==”) in the byte,
c) position of bit(s) in the byte.
Jan 3 '08 #1
11 1644
sicarie
4,677 Recognized Expert Moderator Specialist
Okay, well, I would start with this:
Devise a function to test bits in a byte, and it returns
a) success or failure,
Looks like your teacher is asking for a function prototype to me. That will settle what you are passing to it, and what you are returning from it. Then you can take b and c and use them to develop your algorithm for figuring out what needs to be the definition of the function (how you get what you are returning...)
Jan 3 '08 #2
new4cprog
14 New Member
Okay, well, I would start with this:


Looks like your teacher is asking for a function prototype to me. That will settle what you are passing to it, and what you are returning from it. Then you can take b and c and use them to develop your algorithm for figuring out what needs to be the definition of the function (how you get what you are returning...)
Thanks sicarie. I'm kind of lost on this one. Could you or anyone else give me supporting example(s). I'm not visualizing it. I found it a little bit harder for me.

Thanks again.
Shulapi
Jan 3 '08 #3
sicarie
4,677 Recognized Expert Moderator Specialist
Are you aware of functions - how they perform, what they do, how they are set up?
Jan 3 '08 #4
new4cprog
14 New Member
Are you aware of functions - how they perform, what they do, how they are set up?
sicarie - Sorry, for the similicity of the question.unders tanding the theortical part is a problem but implementing it the problem for me as a beginner. I know in general what function is and what it does: it need to be declared and defined. It has return type, name and arguments, it is called and returns to a caller. ex: int fun (in x, in y).
Jan 3 '08 #5
sicarie
4,677 Recognized Expert Moderator Specialist
No, that's great. So now we apply that to your specific issue. (I would like to point out that while you had an int as a return type, the types of your function parameters were declared as in - they need ints if you want them to hold integers.)

So back to the function - what datatype would be either a success or a failure?

Then, what are you passing to this function to be examined?
Jan 3 '08 #6
new4cprog
14 New Member
No, that's great. So now we apply that to your specific issue. (I would like to point out that while you had an int as a return type, the types of your function parameters were declared as in - they need ints if you want them to hold integers.)

So back to the function - what datatype would be either a success or a failure?

Then, what are you passing to this function to be examined?
I'm not sure but since it says byte, may be character datatype.
Jan 4 '08 #7
sicarie
4,677 Recognized Expert Moderator Specialist
Which was that for? I asked two questions there, which one do you think is a char datatype?
Jan 4 '08 #8
new4cprog
14 New Member
Which was that for? I asked two questions there, which one do you think is a char datatype?
I was thinking char for input since we are testing a bit in a byte and for success or failure that datatype will be int. Can you create one function for me to understand it better. Thanks
Jan 4 '08 #9
sicarie
4,677 Recognized Expert Moderator Specialist
I was thinking char for input since we are testing a bit in a byte and for success or failure that datatype will be int. Can you create one function for me to understand it better. Thanks
Well, I can see a char for the input - then you can compare it to the '1' or '0' char, though dealing in binary would be even easier.

However for the success or failure, I would recommend a boolean (bool) datatype. That return is true or false, while int is usually 0 for false and any other number for true, though it could work either way.
Jan 4 '08 #10

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

Similar topics

21
4222
by: saurabhnsit2001 | last post by:
I have got few questions on bit fiddling!! 1. Fast way of Multiplying a No by 7. 2. Counting no of set bits in a 32 bit no without looping. 3. finding id a no is divisible by 3 or not without using %, /, and - operators,
22
2080
by: dos.fishing | last post by:
Hello, I'm writing a function that should do the following: /** * Calculate and return fraction of valueA where max fractions is 31. * param valueA A five bit value, 0-31. * param valueB The fraction, a five bit value, 0-31. * */
0
1170
by: Twayne | last post by:
Twayne wrote: That's the verification I was looking for I think. There are times that doesn't seem to be so, but perhaps I'll looking at the wrong side of the tree in the wrong forest ... I think I let POST usages confuse me. .... D'oh! No, I hadn't thought of looking at the souce in my browser! Nothing like being half-armed and half-fast, huh? Guess I better switch
5
1142
by: Banibrata Dutta | last post by:
Hi, I've gone through the list of "language differences" between 2.3 / 2.4 & 2.5 of CPython. I've spend around 2 weeks now, learning v2.5 of CPython, and I consider myself still very very newbie. So, unable to take a call as to how-important or desirable the newer language features are -- so whether to write my app for v2.5 of Python, versus, as few others on this list have recommended, i.e. to stick to v2.3 ?? Are the preformance...
16
1882
by: Raxit | last post by:
Hi, i was reading/learning some hello world program in python. I think its very simillar to Java/C++/C#. What's different (except syntax) ? what can i do easily with python which is not easy in c++/java !? Tnx, Raxit
10
1266
by: Peter Michaux | last post by:
On May 14, 8:55 pm, Prisoner at War <prisoner_at_...@yahoo.comwrote: Get it from the library. I cannot imagine needing to own an HTML book. There are plenty of good references on the web. Understand that XHTML is not for the general web. HTML is a better option. I own Eric Meyer's "CSS: The Definitive Guide" and am glad that I do. It is the best definitive guide I've read on any web topic. "Bullet Proof Web Design" is the best book...
2
1250
by: r_ahimsa_m | last post by:
Could you recommend me some free JavaScript validator? I was using JSlint but it reports nonsense errors. Please help. Thanks. /RAM/
0
8991
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
9548
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...
0
9374
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9325
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
9249
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8244
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6076
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
4876
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2215
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.