473,387 Members | 1,582 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Storing (0, 1, -1, U, X) in a variable

i'd like to store values of a signal into a variable called signal.

signal can take 0, 1, -1, U (where u = undefined, -1 = uninitialized)

is there a way i can store this without making the signal a string or
an int (in which case, i have to change the U to another number)

right now i am going with string, but i was wondering what you pros do
in such cases.

by the way, i am going to use these values to do some basic and/or/xor
type operations. (if i use string, i have to keep converting that stuff
before i do anything)

thanks.

Sep 8 '05 #1
3 1270
ma******@gmail.com wrote:
i'd like to store values of a signal into a variable called signal.

signal can take 0, 1, -1, U (where u = undefined, -1 = uninitialized)

is there a way i can store this without making the signal a string or
an int (in which case, i have to change the U to another number)
Do a char. Or a 'signed char'. Or a bit field of two bits. That's as
little as you can have. It will still probably take up as much as an int
in your computer memory. An array of them will probably be smaller...
right now i am going with string, but i was wondering what you pros do
in such cases.
Depends on what you need to do with it afterwards, how many of them you
need store at the same time, etc.
by the way, i am going to use these values to do some basic and/or/xor
type operations. (if i use string, i have to keep converting that stuff
before i do anything)


Same with any other type.

V
Sep 8 '05 #2
ma******@gmail.com wrote:
i'd like to store values of a signal into a variable called signal.

signal can take 0, 1, -1, U (where u = undefined, -1 = uninitialized)

is there a way i can store this without making the signal a string or
an int (in which case, i have to change the U to another number)
(...) by the way, i am going to use these values to do some basic and/or/xor
type operations. (if i use string, i have to keep converting that stuff
before i do anything)

Something like this:

struct Signal
{
enum signal_type {ZERO=0, ONE=1, UNDEF=2, UNINIT=-1} value;

Signal():value(UNINIT) {}

/* define operations */
Signal and(Signal& s) {...}
(...)
};
Sep 8 '05 #3

I'm guessing here, but this looks like the Verilog/VHDL logic
states which you can comfortably encode into a unsigned
char. Why are you using a -1 value, this is a bad choice since
you can do some very nice bit-wise operations to compute logical
expressions of these values which takes into account the "solid"
0,1 values and the undefined/unknown values U & X.

VHDL adopts the rule that the "Leftmost" value is the default (unassigned)
value for a enumeration type, so if you made U = 0, this would be convenient
to implement in C++, (especially with arrays of these babies)
Here's what I'd suggest, so that is in "Binary" you enum type would take
these values.

"U" = 00
"X" = 01
"0" = 00
"1" = 10

As you can see, this makes the logical evaluation of expressions of signals
relatively
easy, you can evaluate the expression using the "known" values ( its a bit
too much
to go into here, but you probably should evaluate the "unknown" part first
to see if
its worth evaluating the "known" part ).

Also in VHDL, an "U" value trumps other values when combined in expressions
( which means you have to do two pairs of bit wise ops on the two sets of
bit positions).
dave
<ma******@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
i'd like to store values of a signal into a variable called signal.

signal can take 0, 1, -1, U (where u = undefined, -1 = uninitialized)

is there a way i can store this without making the signal a string or
an int (in which case, i have to change the U to another number)

right now i am going with string, but i was wondering what you pros do
in such cases.

by the way, i am going to use these values to do some basic and/or/xor
type operations. (if i use string, i have to keep converting that stuff
before i do anything)

thanks.

Sep 9 '05 #4

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

Similar topics

2
by: Francisco | last post by:
I have this problem: I have a database with information about games, and users are able to vote for them. Everytime a user votes for a game I store the unique game name into a session variable (an...
3
by: dave | last post by:
Hello there, I am at my wit's end ! I have used the following script succesfully to upload an image to my web space. But what I really want to be able to do is to update an existing record in a...
3
by: Sean | last post by:
HI, I have a shopping cart in which I am trying to use breadcrumb style navgiation. I need to be able to display the categroy heading relating to the section of the site a visitor is using i.e...
12
by: Alfonso Morra | last post by:
I have the ff code for testing the concept of storing objects: #include <vector> #include <iostream> using namespace std ; class MyClass { public: MyClass(){
0
by: Sandra | last post by:
I am using a VB6 COM object with an asp.net project. I am storing the COM object in a session variable but am having a problem accessing the COM object from the session variable. I am getting...
4
by: Frank Rizzo | last post by:
In classic ASP, it was considered a bad idea to store VB6-created objects in the Application variable for various threading issues. What's the current wisdom on storing objects in the Application...
2
by: Angel | last post by:
I am storing a value into a javascript variable that was keyed into a text control. When the code performs a postback, the value that was stored into a clientside variable no longer exists. Is...
2
by: newjazzharmony | last post by:
All, I'd appreciate it if someone could answer these questions for me. This scenario applies to an ASP dot net application that is deployed in a web farm. 1) Does the application live in a...
1
by: None | last post by:
Hi, I have developed webshop application using asp.net 1.1. I'm using DataGrid in one of the pages of my site. During the page load the DataGrid will be binded by around 7500 products(rows). At...
3
by: RSH | last post by:
Hi, I have a situation where I have created an object that contains fields,properties and functions. After creating the object I attempted to assign it to a session variable so i could retrieve...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...

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.