What's the opposite of od(1)?
Use:
% xxd -r -p in.txt out.bin
Hexdump reverse command
There is a similar tool called xxd
. If you run xxd
with just a file name it dumps the data in a fairly standard hex dump format:
# xxd bdata
0000000: 0001 0203 0405
......
Now if you pipe the output back to xxd
with the -r
option and redirect that to a new file, you can convert the hex dump back to binary:
# xxd bdata | xxd -r >bdata2
# cmp bdata bdata2
# xxd bdata2
0000000: 0001 0203 0405
Should I use != or for not equal in T-SQL?
Technically they function the same if you’re using SQL Server AKA T-SQL. If you're using it in stored procedures there is no performance reason to use one over the other. It then comes down to personal preference. I prefer to use <> as it is ANSI compliant.
You can find links to the various ANSI standards at...
http://en.wikipedia.org/wiki/SQL
In C/C++ what's the simplest way to reverse the order of bits in a byte?
If you are talking about a single byte, a table-lookup is probably the best bet, unless for some reason you don't have 256 bytes available.
CSS Units - What is the difference between vh/vw and %?
100%
can be 100%
of the height of anything. For example, if I have a parent div
that's 1000px
tall, and a child div
that is at 100%
height, then that child div
could theoretically be much taller than the height of the viewport, or much smaller than the height of the viewport, even though that div
is set at 100%
height.
If I instead make that child div
set at 100vh
, then it'll only fill up 100%
of the height of the viewport, and not necessarily the parent div
.
body,html { height: 100%;}
.parent { background: lightblue; float: left; height: 200px; padding: 10px; width: 50px;}
.child { background: pink; height: 100%; width: 100%;}
.viewport-height { background: gray; float: right; height: 100vh; width: 50px;}
<div class="parent"> <div class="child"> 100% height (parent is 200px) </div></div>
<div class="viewport-height"> 100vh height</div>
Regular cast vs. static_cast vs. dynamic_cast
static_cast
static_cast
is used for cases where you basically want to reverse an implicit conversion, with a few restrictions and additions. static_cast
performs no runtime checks. This should be used if you know that you refer to an object of a specific type, and thus a check would be unnecessary. Example:
void func(void *data) {
// Conversion from MyClass* -> void* is implicit
MyClass *c = static_cast<MyClass*>(data);
...
}
int main() {
MyClass c;
start_thread(&func, &c) // func(&c) will be called
.join();
}
In this example, you know that you passed a MyClass
object, and thus there isn't any need for a runtime check to ensure this.
dynamic_cast
dynamic_cast
is useful when you don't know what the dynamic type of the object is. It returns a null pointer if the object referred to doesn't contain the type casted to as a base class (when you cast to a reference, a bad_cast
exception is thrown in that case).
if (JumpStm *j = dynamic_cast<JumpStm*>(&stm)) {
...
} else if (ExprStm *e = dynamic_cast<ExprStm*>(&stm)) {
...
}
You can not use dynamic_cast
for downcast (casting to a derived class) if the argument type is not polymorphic. For example, the following code is not valid, because Base
doesn't contain any virtual function:
struct Base { };
struct Derived : Base { };
int main() {
Derived d; Base *b = &d;
dynamic_cast<Derived*>(b); // Invalid
}
An "up-cast" (cast to the base class) is always valid with both static_cast
and dynamic_cast
, and also without any cast, as an "up-cast" is an implicit conversion (assuming the base class is accessible, i.e. it's a public
inheritance).
Regular Cast
These casts are also called C-style cast. A C-style cast is basically identical to trying out a range of sequences of C++ casts, and taking the first C++ cast that works, without ever considering dynamic_cast
. Needless to say, this is much more powerful as it combines all of const_cast
, static_cast
and reinterpret_cast
, but it's also unsafe, because it does not use dynamic_cast
.
In addition, C-style casts not only allow you to do this, but they also allow you to safely cast to a private base-class, while the "equivalent" static_cast
sequence would give you a compile-time error for that.
Some people prefer C-style casts because of their brevity. I use them for numeric casts only, and use the appropriate C++ casts when user defined types are involved, as they provide stricter checking.
Related Topics
Intellij Idea Under Linux, No Such File or Directory on Main Class
Append The Time Stamp to a File Name in Ubuntu
How to Get Ctrl-Backspace to Delete a Word in Vim Within Gnome-Terminal
Adding Support for Menuconfig/Kconfig in My Project
Smbclient - Send All Files in Directory
Tomcat Intellij Idea: Remote Deploy
Conda.Exe: Error While Loading Shared Libraries: Libz.So.1
Linux Os: /Proc/[Pid]/Smaps Vs /Proc/[Pid]/Statm
Wget-Like Bittorrent Client or Library
Minimizing Copies When Writing Large Data to a Socket
Understanding Tcpdump Filter & Bit-Masking
What Is The Significance of This_Module in Linux Kernel Module Drivers
Manage Source Under Git and Svn Simultanously - Does It Make Sense
Difference Between Tcp_Max_Syn_Backlog and Somaxconn
Cross Compiling for Mips Router from X86
Does Kernel's Panic() Function Completely Freezes Every Other Process