473,748 Members | 5,230 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can some one help with this problem of bits?

Dear all,
I have one peculiar problem with me for which I need ur inputs how
to implement it:

I have 2 registers each 8 bit wide.

The first register stores:

Register Map:
_______________ _______________ __ Can be zero or 1.
|
0 0/1 N10 N9 N8 N7 N6 N5-Reg1
N4 N3 N2 N1 0 1 0 0 -Reg2 For other then N10 to N1 values in bits
are constants.

Now the problem is I have calculated value of N and when N is
expressed in binary in 10 bits,I will get N10-N1 bits.How to fill them
in this registers?
What sort of binary arithmetic should I use to fill the details in
this registers. Can some one let me know some logic to do this in a
efficient manner?

What sort of datatype is suitable to store N ?Which type of data will
make it more efficient in storing?

One more problem here is I want to give user the freedom to change
value of 2nd bit(shown as 0/1 in register map above).How to achieve
this in code?

expecting ur reply and advanced thanks,
Regards,
s.subbarayan
Nov 14 '05 #1
2 1220
Hiho,
I have one peculiar problem with me for which I need ur inputs how
to implement it:

I have 2 registers each 8 bit wide.

The first register stores:

Register Map:
_______________ _______________ __ Can be zero or 1.
|
0 0/1 N10 N9 N8 N7 N6 N5-Reg1
N4 N3 N2 N1 0 1 0 0 -Reg2 For other then N10 to N1 values in bits
are constants.

Now the problem is I have calculated value of N and when N is
expressed in binary in 10 bits,I will get N10-N1 bits.How to fill them
in this registers?
What sort of binary arithmetic should I use to fill the details in
this registers. Can some one let me know some logic to do this in a
efficient manner?
Write it down, go through systematically. Below is a possible way; I did
not test it, though

In your header:
/* RegHi
** Bits:
** 0-5 N5-N10
** 6 Toggle
** 7 0
*/

/* RegLo
** Bits:
** 0-3 0x4
** 4-7 N1-N4
*/

#define N_LO_SHIFT 4
#define N_HI_SHIFT 4

#define N_LO_MASK 0xF
#define N_HI_MASK 0x3F0

#define LO_FIXED (1<<2)
#define HI_FIXED (0<<7)

#define TOGGLE_SHIFT 6
#define TOGGLE_MASK 0x1

#define MAKE_LO(n) 0xFF & (LO_FIXED\
| (((n)&N_LO_MASK )<<N_LO_SHIFT)

#define MAKE_HI(n,toggl e) 0xFF & (HI_FIXED\
| (((n)&N_HI_MASK )>>N_HI_SHIFT) \
| (((toggle)&TOGG LE_MASK)<<TOGGL E_SHIFT)

In your program
reghi = MAKE_HI(my_n,1)
reglo = MAKE_LO(my_n)

What sort of datatype is suitable to store N ?Which type of data will
make it more efficient in storing?
C99: uint8_t or uint_fast8_t (<stdint.h>)
otherwise: unsigned char

If you want, you can of course use a >=16 bit (unsigned) datatype.

One more problem here is I want to give user the freedom to change
value of 2nd bit(shown as 0/1 in register map above).How to achieve
this in code?


Taken care of. The mask does not make sense for a toggle bit, you might
want to change that part of MAKE_HI to
| ((_Bool)(toggle )<<TOGGLE_SHIFT )

Once more: Only an untested example.
Cheers,
Michael

Nov 14 '05 #2
Hiho,

I have one peculiar problem with me for which I need ur inputs how
to implement it:

I have 2 registers each 8 bit wide.

The first register stores:

Register Map:
_______________ _______________ __ Can be zero or 1.
|
0 0/1 N10 N9 N8 N7 N6 N5-Reg1
N4 N3 N2 N1 0 1 0 0 -Reg2 For other then N10 to N1 values in bits
are constants.

Now the problem is I have calculated value of N and when N is
expressed in binary in 10 bits,I will get N10-N1 bits.How to fill them
in this registers?
What sort of binary arithmetic should I use to fill the details in
this registers. Can some one let me know some logic to do this in a
efficient manner?
Write it down, go through systematically. Below is a possible way; I did
not test it, though

In your header:
/* RegHi
** Bits:
** 0-5 N5-N10
** 6 Toggle
** 7 0
*/

/* RegLo
** Bits:
** 0-3 0x4
** 4-7 N1-N4
*/

#define N_LO_SHIFT 4
#define N_HI_SHIFT 4

#define N_LO_MASK 0xF
#define N_HI_MASK 0x3F0

#define LO_FIXED (1<<2)
#define HI_FIXED (0<<7)

#define TOGGLE_SHIFT 6
#define TOGGLE_MASK 0x1

#define MAKE_LO(n) 0xFF & (LO_FIXED\
| (((n)&N_LO_MASK )<<N_LO_SHIFT)

#define MAKE_HI(n,toggl e) 0xFF & (HI_FIXED\
| (((n)&N_HI_MASK )>>N_HI_SHIFT) \
| (((toggle)&TOGG LE_MASK)<<TOGGL E_SHIFT)

In your program
reghi = MAKE_HI(my_n,1)
reglo = MAKE_LO(my_n)

What sort of datatype is suitable to store N ?Which type of data will
make it more efficient in storing?
I cannot tell you that without knowing what kind of registers these
are. If you need to be free of alignment issues: unsigned char.
Without any restrictions:
C99: uint8_t or uint_fast8_t (<stdint.h>)
otherwise: unsigned char

If you want and this is possible, you can of course use a >=16 bit
(unsigned) datatype for storing both registers. However, without
more information I cannot tell anysthing.

One more problem here is I want to give user the freedom to change
value of 2nd bit(shown as 0/1 in register map above).How to achieve
this in code?


Taken care of. The mask does not make sense for a toggle bit, you might
want to change that part of MAKE_HI to
| ((_Bool)(toggle )<<TOGGLE_SHIFT )

Once more: Only an untested example.
Cheers,
Michael

Nov 14 '05 #3

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

Similar topics

2
3181
by: Grumfish | last post by:
In order to familiarize my self with Flash files and their bytecode I've started to make an assembler. My first problem is writing the bitfields the format uses often. It is a series of fields, each can be a different number of bits, combined into the least amount of bytes possible. Extra bits in the last byte are padded with zeros. I would like to make a function that takes a size and value for each field needed, calculate the amount of...
6
4007
by: Brian K. Michalk | last post by:
I have a perl app that is calculating the standard deviation of a 4000 element 16 bit integer array, that has large dynamic content. I.e, the range spans a significant portion of the 16 bits. I am trying to increase the performance of this critical loop, and I've found that I am exceeding the 32 bit registers causing Perl to switch to an infinite precision math library. I've rewritten the loop such that I now have only one term that...
4
2246
by: Andre Paim Lemos | last post by:
Hi, I'm having some compiler problems when I try to use make_heap(), push_heap() and pop_heap(). I am compiling my code on gcc version 3.3.1 (SuSE Linux). I am using the heap related methods to create a priority queue on a list of objects ordered by the objectId. The problem is that the compiler says that I have to implement the operator- on my object.
2
1848
by: Joel | last post by:
I am having some problems compiling my code on Mandrake 10 with g++ (GCC 3.3.2). The problem seems to be in that I try to define a functor that compares two pointer objects, and use that functor to sort a list of pointers. It seems correct to me, and when I read on these boards I could not find any one complaining about the same problem. But my compiler is giving me error messages. I am hoping that someone can help to point out where my...
36
2689
by: Profetas | last post by:
Hi, I want to generate a random 8 bit number using rand(0 is that possible? to expecifu the base and the lenght? thanks
11
1709
by: bogusexception | last post by:
(or.. "I'm getting too much Tails and not enough Heads") I'm running into a very strange problem with random numbers and long numbers. To demonstrate the problem, I've created a simple test. Consider that a series of coins are to be "flipped" all at once. The result of the combined flip are a series of bits (0 = tails or 1=heads). These bits form a number, and that number can be represented by a type long. OK. Not so bad so far. To...
29
3273
by: Halid Umar A M | last post by:
Hi All, I m Halid Umar, network security research student. I will explain my situation and give me hint if you can. I expect reply from you all. * I have to handle numbers that have more than 64 bit like 128bit in cryptography applications. * For example, if i want to add two 128 bit numbers what should i do in C.
2
1351
by: skalig1 | last post by:
Hey the title was just to attract people to my problem.......well my problem is .... i code in vc++ and i have a situation which is like this....... i have a buffer which holds data in the form of 8bits+8bits+8bits+8bits..... i have to transmit the first 8 bits as it is and i have to insert 4 bits in the middleand then 8 bits and then 4 bits and so on........
39
3569
by: rembremading | last post by:
Hi all! The following piece of code has (for me) completely unexpected behaviour. (I compile it with gcc-Version 4.0.3) Something goes wrong with the integer to float conversion. Maybe somebody out there understands what happens. Essentially, when I subtract the (double) function value GRID_POINT(2) from a variable which has been assigned the same value before this gives a non-zero result and I really do not understand why.
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
8830
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,...
0
9372
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
9324
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
8243
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
6074
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
4606
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...
1
3313
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
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.