473,703 Members | 2,420 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 1638
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
4218
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
2073
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
1169
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
1140
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
1878
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
1261
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
1249
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
8657
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8988
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
8946
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...
1
6580
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4415
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
4672
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3108
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
2411
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2044
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.