Signup/Sign In

Answers

All questions must be answered. Here are the Answers given by this user in the Forum.

This is another solution for folks who love recursion.

The idea is simple. Divide up input by half and swap the two halves, continue until it reaches single bit.

***Illustrated in the example below.

Ex : If Input is 00101010 ==> Expected output is 01010100

1. Divide the input into 2 halves
0010 --- 1010

2. Swap the 2 Halves
1010 0010

3. Repeat the same for each half.
10 -- 10 --- 00 -- 10
10 10 10 00

1-0 -- 1-0 --- 1-0 -- 0-0
0 1 0 1 0 1 0 0

Done! Output is 01010100***
Here is a recursive function to solve it. (Note I have used unsigned ints, so it can work for inputs up to sizeof(unsigned int)*8 bits.

The recursive function takes 2 parameters - The value whose bits need to be reversed and the number of bits in the value.

***int reverse_bits_recursive(unsigned int num, unsigned int numBits)
{
unsigned int reversedNum;;
unsigned int mask = 0;

mask = (0x1 << (numBits/2)) - 1;

if (numBits == 1) return num;
reversedNum = reverse_bits_recursive(num >> numBits/2, numBits/2) |
reverse_bits_recursive((num & mask), numBits/2) << numBits/2;
return reversedNum;
}

int main()
{
unsigned int reversedNum;
unsigned int num;

num = 0x55;
reversedNum = reverse_bits_recursive(num, 8);
printf ("Bit Reversal Input = 0x%x Output = 0x%x\n", num, reversedNum);

num = 0xabcd;
reversedNum = reverse_bits_recursive(num, 16);
printf ("Bit Reversal Input = 0x%x Output = 0x%x\n", num, reversedNum);

num = 0x123456;
reversedNum = reverse_bits_recursive(num, 24);
printf ("Bit Reversal Input = 0x%x Output = 0x%x\n", num, reversedNum);

num = 0x11223344;
reversedNum = reverse_bits_recursive(num,32);
printf ("Bit Reversal Input = 0x%x Output = 0x%x\n", num, reversedNum);
}
This is the output:

Bit Reversal Input = 0x55 Output = 0xaa
Bit Reversal Input = 0xabcd Output = 0xb3d5
Bit Reversal Input = 0x123456 Output = 0x651690
Bit Reversal Input = 0x11223344 Output = 0x22cc4488***
3 years ago
If this is what you mean, you can simply extend the class you would like to typedef, e.g.:

***public class MyMap extends HashMap {}***
3 years ago
It has already been stated that the **extern** keyword is redundant for functions.

As for variables shared across compilation units, you should declare them in a header file with the extern keyword, then define them in a single source file, without the extern keyword. The single source file should be the one sharing the header file's name, for best practice.
3 years ago
No need to be complex. The simplest and framework manner is to use **ACCESS_NETWORK_STATE** permission and just make a connected method

***public boolean isOnline() {
ConnectivityManager cm =
(ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);

return cm.getActiveNetworkInfo() != null &&
cm.getActiveNetworkInfo().isConnectedOrConnecting();
}***
You can also use **requestRouteToHost** if you have a particualr host and connection type (wifi/mobile) in mind.

You will also need:

******
in your android manifest.
3 years ago
I check for both Wi-fi and Mobile internet as follows...

***private boolean haveNetworkConnection() {
boolean haveConnectedWifi = false;
boolean haveConnectedMobile = false;

ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo[] netInfo = cm.getAllNetworkInfo();
for (NetworkInfo ni : netInfo) {
if (ni.getTypeName().equalsIgnoreCase("WIFI"))
if (ni.isConnected())
haveConnectedWifi = true;
if (ni.getTypeName().equalsIgnoreCase("MOBILE"))
if (ni.isConnected())
haveConnectedMobile = true;
}
return haveConnectedWifi || haveConnectedMobile;
}***
3 years ago
In the AndroidManifest I found this parameter:

***android:networkSecurityConfig="@xml/network_security_config"***

and @xml/network_security_config is defined in network_security_config.xml as:

***



***
just I changed cleartextTrafficPermitted to true
3 years ago
The content is put after the HTTP headers. The format of an HTTP POST is to have the HTTP headers, followed by a blank line, followed by the request body. The POST variables are stored as key-value pairs in the body.

You can see this in the raw content of an HTTP Post, shown below:

***POST /path/script.cgi HTTP/1.0
From: xyz@abc.com
User-Agent: HTTPTool/1.0
Content-Type: application/x-www-form-urlencoded
Content-Length: 32

home=Cosby&favorite+flavor=flies***
3 years ago
***SELECT COUNT(DISTINCT program_name) AS Count, program_type AS [Type]
FROM cm_production
WHERE push_number=@push_number
GROUP BY program_type***
3 years ago
If you have no references, like foreign keys, you can do this. I do it a lot when testing proofs of concept and the test data gets duplicated.

***SELECT DISTINCT [col1],[col2],[col3],[col4],[col5],[col6],[col7]

INTO [newTable]

FROM [oldTable]***

Go into the object explorer and delete the old table.

Rename the new table with the old table's name.
3 years ago
HTML
***
<%# (Eval("Name").ToString().Length > 65) ? Eval("Name").ToString().Substring(0, 60) + "..." : Eval("Name")%>

<%# (Eval("Name").ToString().Length > 65) ? "More" : "" %>

<%# Eval("Name") %>


***

CSS

***.showonhover .hovertext { display: none;}
.showonhover:hover .hovertext {display: inline;}
a.viewdescription {color:#999;}
a.viewdescription:hover {background-color:#999; color: White;}
.hovertext {position:absolute;z-index:1000;border:1px solid #ffd971;background-color:#fffdce;padding:11px;width:150px;font-size: 0.75em;}***
3 years ago
You can try this:

***var results = from c in db.Companies
join cn in db.Countries on c.CountryID equals cn.ID
join ct in db.Cities on c.CityID equals ct.ID
join sect in db.Sectors on c.SectorID equals sect.ID
where (c.CountryID == cn.ID) && (c.CityID == ct.ID) && (c.SectorID == company.SectorID) && (company.SectorID == sect.ID)
select new { country = cn.Name, city = ct.Name, c.ID, c.Name, c.Address1, c.Address2, c.Address3, c.CountryID, c.CityID, c.Region, c.PostCode, c.Telephone, c.Website, c.SectorID, Status = (ContactStatus)c.StatusID, sector = sect.Name };


return results.ToList();***
3 years ago
**Trigger** and **Sequence** can be used when you want serialized number that anyone can easily read/remember/understand. But if you don't want to manage ID Column (like emp_id) by this way, and value of this column is not much considerable, you can use **SYS_GUID()** at Table Creation to get Auto Increment like this.

***CREATE TABLE
(emp_id RAW(16) DEFAULT SYS_GUID() PRIMARY KEY,
name VARCHAR2(30));***

Now your **emp_id** column will accept "globally unique identifier value". you can insert value in table by ignoring emp_id column like this.

***INSERT INTO (name) VALUES ('name value');***

So, it will insert unique value to your **emp_id** Column.
3 years ago