Hex Puzzlement (take 2)
From: cfk (cfk_alter_ego_at_pacbell.net)
Date: 11/29/03
- Next message: Helmut Giese: "Re: Hex Puzzlement (take 2)"
- Previous message: Robert Heller: "Re: for problem..."
- Next in thread: Helmut Giese: "Re: Hex Puzzlement (take 2)"
- Reply: Helmut Giese: "Re: Hex Puzzlement (take 2)"
- Reply: Benjamin Riefenstahl: "Re: Hex Puzzlement (take 2)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sat, 29 Nov 2003 22:11:12 GMT
I have a register in my chip called QBT where the upper 16 bits represent
the throughput in megabaud. I have a modest script that I *thought* would
give me 0x0001 for the first value and hex 0x8002 for the second that I can
then process further and put up with an indicator to show the hardware guys
what the throughput is for our testing. The fact that it gives me 0xFFFF8002
for the second escapes me. Perhaps someone would show me the errors of my
ways?
Humbly Yours, Charles
SCRIPT
foreach qbt { "0001FFFF" "8002FFFF" } {
set thruput [format %08X [expr "0x$qbt & 0xFFFF0000 >> 16" ]]
#this should have shifted left 16 bits the field I want, but it dunt
puts -nonewline "qbt:$qbt thru1:$thruput "
set thruput [format %04X [expr "0x$thruput >> 16"]]
puts "thru2$thruput "
}
The result of the script is:
qbt:0001FFFF thru1:0001FFFF thru2:0001
qbt:8002FFFF thru1:8002FFFF thru2:FFFF8002
There are two problems here. The first is that the first >> 16 seems to be
ignored. The second is that whenever the hi bit is set in qbt coming into
this routine, Tcl insists on setting all the hi-bits. It must be that Tcl
thinks this is a negative number. Unfortunately, its just a bitfield and
incidently, always an unsigned 16bit number.
- Next message: Helmut Giese: "Re: Hex Puzzlement (take 2)"
- Previous message: Robert Heller: "Re: for problem..."
- Next in thread: Helmut Giese: "Re: Hex Puzzlement (take 2)"
- Reply: Helmut Giese: "Re: Hex Puzzlement (take 2)"
- Reply: Benjamin Riefenstahl: "Re: Hex Puzzlement (take 2)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]