Category Archives: software & technology - Page 2

Verilog assign command

I was unhappy the way Verilog’s assign command was described online. Therefore I would like to share my way to explain it. It’s actually damn simple

assign is described as ‘continuous assignment statement’. Therefore, when you assign a register to a wire, it keeps bind forever. Assigning a to b and changing b means changing a. Be aware, that the left term has to be a wire and the right one has to be some sort of value container (eg. reg). So assigning a value to a is not possible.

module assign_test();
  wire [7:0] a;
  reg [15:0] b = 'h3;
 
  // a reads bits 7 to 0 of b
  assign a = b[7:0];
  // modify b 5 time units later
  always b = #5 b + 'hA;
 
  always #10 $display("reg b is %h", b);
  always #10 $display("wire a is %h", a);
  initial #21 $finish();
endmodule

The output is:

reg b is 000d
wire a is 0d
reg b is 0021
wire a is 21

PHP Accessing elements by reference

Input:
$a = array();
$b = $a['a'];
var_dump($a);

Output:
array(0) { }

Input:
$a = array();
$b = &$a['a'];
var_dump($a);

Output:
array(1) { ["a"]=> &NULL }

Accessing elements modifies state. I hate this.

Sagemath plot fail


Sagemath Plot fail

I think mathlibplot is responsible :-(

Happy Easteregg

Milestones in learning a programming language :-) … at least my experience.


Steps in learning a programming language

[SVG-Version]

Definitions in character terminology

I would like to sum up the terminology (as far as I understand it):

Mojibake
Character in encoding X was decoded using encoding Y
glyph
A character / symbol identified by its shape
character
A digital representation of a glyph as code point
code point
An integer (mostly listed as hex code) representing / referring to a character
charset (abbr. character set)
A set of associations between code points and characters
encoding
A set of conventions to transform a code point to a byte string (always in respect of a charset)
character string
A string with 1 glyph / character as a unit
byte string
Character string encoded (in a specific encoding)

For example, the glyph A consists of three lines and is the first letter in the latin alphabet (which defines a set of characters). If you put two dots at its top (Ä) and decode its UTF-8 representation as latin1, you will get a mojibake Ü. The A’s code point in ASCII-compliant encodings such as Unicode is 65 (0×41). The charset UTF-8 defines the association between 65 and A and for charset UTF-8, the encoding is Unicode. Only 1 byte is required to store 0×41 in the memory (in UTF-8 charset) which is binary 101010. So the bytestring of A looks like this in binary: (01000001, ).

On the issue of float, double and long

#include <stdio.h>
// Test environment:
//    Thinkpad Lenovo x201 -- 64bit, gcc 4.5.1, Linux Fedora

int main()
{
  // [0] error: both ‘long’ and ‘float’ in declaration specifiers
  // [1] error: both ‘long long’ and ‘double’ in declaration specifiers

  int a = 1;
  long int b = 1;
  int long c = 1;
  long long int d = 1;
  int long long e = 1;

  float f = 1.0;
  //float long g = 1.0; // [0]
  //long float h = 1.0; // [0]
  //float long long i = 1.0; // [0] [0]
  //long long float j = 1.0; // [0]

  double o = 1.0;
  long double p = 1.0;
  double long q = 1.0;
  //long long double r = 1.0; // [1]
  //double long long s = 1.0; // [1]

  printf("%zun", sizeof(a)); // 4
  printf("%zun", sizeof(b)); // 8
  printf("%zun", sizeof(c)); // 8
  printf("%zun", sizeof(d)); // 8
  printf("%zun", sizeof(e)); // 8
  printf("%zun", sizeof(f)); // 4
  printf("%zun", sizeof(o)); // 8
  printf("%zun", sizeof(p)); // 16
  printf("%zun", sizeof(q)); // 16
  printf("%lfn", o); // 1.000000
  return 0;
}
  1. Why is “double” not “long float”? Replace “double” with “float long” in the example above and you will recognize some consistency.
  2. See the line before “return 0″. Double is semantically a “long float” for printf.
  3. Why is the error of “float long long” printed twice?
  4. As everybody should know, datatypes of C are not bound to any length of size. [wiki]
  5. According to GCC, “float” is defined as “float” < “double” < “double long” with a radix of 2
  6. I don’t like C :-(

Probably, maybe, …

The canPlayType() function doesn’t return true or false. In recognition of how complex video formats are, the function returns a string:

  • "probably" if the browser is fairly confident it can play this format
  • "maybe" if the browser thinks it might be able to play this format
  • "" (an empty string) if the browser is certain it can’t play this format

:-D Sounds like an easteregg, but isn’t…

via Dive into HTML5: Video formats

What C needs…

  • no undefined behaviour (prefer Compile Errors over strange behaviour)
  • Garbage Collector (reference counter)
  • Polymorphism / Multimethods (function identifier by signature / API)
  • no NULL terminated strings
  • Namespaces

thanks for the discussion, name

C and printf

#include <stdio.h>

int main()
{
  unsigned int x = 0;
  unsigned int y = x - 1;
  printf("%d n", y);
  printf("%d n", y < 0);
  return 0;
}

Ausgabe?

-1
0

C is evil :-(

The Right Tool: Python vs. PHP

This article is one year old. Accidently I did not post it in the past. So here we go with an updated version.

The Right Tool offers a nice survey, asking to rank the programming languages you select, in a suitable order related to a statement (2705 9383 programmers did it yet). Even though, I think I have experience with several languages, I was interested in comparing my “two Big Ones” (PHP and Python). And these are the results of the survey:

PHP vs Python - Programming Languages

PHP vs. Python [outdated]

Note: For PHP “ranked highly” number 3 stands for “The thought that I may still be using this language in twenty years time fills me with dread” and “ranked low” number 3 voted to number 1. For Python “ranked highly” number 2 states “This language would be good for teaching children to write software” and “ranked low” number 3 says “This language has an annoying syntax” today… oder checkout PHP and python

The PHP community is not that self esteemed like the Python community. Even though many programmers rank Python as an “unusual bad language for beginners” language, Python is listed as one of the “best languages for beginners”. On the other hand, we have what I love about python and is listed as number 1 number 5 in comparison to other languages:

This programming language has an annoying syntax
Note: Cobol is to the left and Scheme to the right today.